Using Android UIL, How to stop the download?

I use UIL ( Nosotra ) to load the images that the server displays, and the server takes up to 50 seconds to create each image. The server timeout is set to 15 seconds, so we created a polling mechanism that is implemented in the ImageDownloader.getStream() method. Once downloaded, the images are displayed in the ViewPager ( android.support.v4.view.ViewPager , same as sample .)

When users go to other pages, I want to stop polling without downloading files, but there seems to be no β€œnice” way to break the download stream.

Pseudocode getStream

 1. Parse custom-style URI ("asdf://mypng|123455678945643563245"); 2. Make a real world URL from it. 3. Poll the server for the image url (causes the server to render - could take up to 1m30s). 4. Get the stream from the URL, return the stream to caller. Example Code: InputStream is = (InputStream) url.getContent(); 

What has been done so far

Returning null from my getStream method throws a NullPointerException , so it is basically the same as a simple exception.

When an exception is thrown, the image stops, but:

  • A few images later, I get an OutOfMemoryError , so I am showing an error on the screen. I should not get an error. I already tried this SO question checklist , but nothing worked. This is Stacktrace OOM: OutOfMemoryError stacktrace nostra uil
  • Downloading stops, and if the viewer does not process the view, when I return to this page, I will still see this page with an error (do not try again).

What I want

I want to have a β€œwait” method that would add to stop the current download and add the new task to the end of the queue again (currently set to QueueProcessingType.LIFO , and I want it to load re-add after subsequent pages and any new pages that the user wants should take precedence over re-added pages).

I would also decide to avoid OutOfMemoryError .

Please, help.

+6
source share
1 answer

The problem may be here. 4. Download the image, return the stream. Download is the main feature of UIL. Just get NetworkStream back here. I also had OOM on UIL with large images and MemoryCache enabled. Also what size image you have on the server. in boot mode. You have control over the size. UIL GitHub is also useful, please read paragraphs 3 and 4.

+1
source

Source: https://habr.com/ru/post/981982/


All Articles