Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Android-UIL, How to stop downloading?

I'm using UIL (by Nosotra) to download images that the server renders, and it takes the server up to 50 seconds to create each image. The server's timeout is set to 15 seconds, so we've created a polling mechanism that is implemented in the ImageDownloader.getStream() method. After downloading, the images are displayed in a ViewPager (android.support.v4.view.ViewPager, just as the sample does.)

When users navigate to other pages, I wish to stop the polling without downloading files, but it seems there's no "nice" way to break the downloading flow.

getStream Pseudo-code

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's tried so far

Returning null from my getStream method causes an NullPointerException to be thrown, so it's basically same as just throwing an exception.

When an exception is thrown, the image does stop, but:

  1. A few images later, I get an OutOfMemoryError, so I show an error on screen. I shouldn't get the error. I already tried this SO question's checklist, but nothing worked. This is the OOM Stacktrace:OutOfMemoryError stacktrace nostra uil
  2. The downloading stops, and if the viewer won't recycle the view, when returning to that page, I'll still see that error page (no retry).

What I wish

I wish for me to have a "wait" method that would add stop the current download and re-add a new task to the end of the queue (currently on set on a QueueProcessingType.LIFO, and I wish it to download the re-added after after current pages, and any new pages the user wants should have precedence over the re-added ones).

I would also settle for avoiding the OutOfMemoryError.

Please help.

like image 890
Felix Avatar asked Feb 04 '15 14:02

Felix


1 Answers

Problem could be here 4. Download the image, return the stream. Downloading - it is main feature of UIL. Just return the NetworkStream here. Also I had OOM on UIL with large Images and enabled MemoryCache. Also which image size do you have on server. in load Image method you have control on Size. Also so helpful UIL GitHub please read 3 and 4 paragraph.

like image 96
TAC Avatar answered Nov 02 '22 19:11

TAC