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: 
- 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.
Felix source share