developer.android.com/training bitmapfun project
Asked Answered
G

1

6

I am using bitmapfun project () in my application and while i was testing this i found a problem. The steps to reproduce this problem are the following:

  1. Open wifi -> launch app -> download images (It works fine).
  2. Close app (back button), deactivate wifi -> activate data network -> relaunch app (Still works fine).
  3. Before all the images were download, i close the app(back button) -> deactivate data network -> activate wifi. After this step when i relaunch the application the images doesn't download.

In the logcat i see that all images are being canceled in imageWorker's cancelPotentialWork() and they never start. My guess is that something is happening with the previous bitmapworkerTask(responsible for download) and there is a collision with the new task. In my app when the is pressed i clear all the caches. But this isn't the cause of the problem because i also tested the same scenario in the original bitmapfun and the problem also appeared! How can i fix this problem? I also changed the multi-threading of the project into a single thread! Is there any possible way to clear all imageview references and cancel all running tasks?

Sorry for my english and for not giving more information about the nature of the bitmapfun project but it will extend my question very much!Ask me anything!

Edit: In order to reproduce the problem maybe is better to clear the cache every time you leave the activity with the menu option. Also it is not sure that the problem will appear if you follow steps 1-3 one time. Maybe you have to repeat them!

Edit2(Additional Help): When i start the activity without problem the logcat for the first image is the following:

04-24 02:31:56.400: D/ImageWorker(25625): doInBackground - starting work
04-24 02:31:56.400: D/ImageFetcher(25625): processBitmap - https://lh3.googleusercontent.com/--L0Km39l5J8/URquXHGcdNI/AAAAAAAAAbs/3ZrSJNrSomQ/s160-c/Antelope%252520Butte.jpg
04-24 02:31:56.400: D/ImageFetcher(25625): processBitmap, not found in http cache, downloading...

and when i start the activity with problem the logcat is this:

04-24 02:28:07.970: D/ImageWorker(24014): cancelPotentialWork - cancelled work for https://lh3.googleusercontent.com/--L0Km39l5J8/URquXHGcdNI/AAAAAAAAAbs/3ZrSJNrSomQ/s160-c/Antelope%252520Butte.jpg

Why in the second case when the cancelPotentialWork has been called the doInBackground never start? According to the sequence of code this is the next part which should be executed!Has anyone at least any idea where i should search for the error?

Ginzburg answered 19/4, 2013 at 16:5 Comment(1)
i can't understand what the problem is.For every new bitmaworkertask i add it to a list and when i exit the activity i cancel all the tasks in that list in order to be sure that no pending task affects the activity when i relaunch it. Also for every asyncDrawable i change the bitmapWorkerTaskReference to null in order to be sure that it hasn't any bitmapWorkerTask reference which hasn't been garbage collected. My goal is to simulate the conditions when the activity first starts and everything works fine. But after all that, the problem still exists!Ginzburg
S
2

what happen to u is OK. Because the ImageFetcher load image when OnCreate(), but cancel by the network deactivate. it does not contain auto restart code. So if u want the loading auto restart, add code to detective the network's state change. I don't think it sensitive . Just let user to restart it by click sometiong like refresh button etc.

Sift answered 22/4, 2013 at 13:50 Comment(1)
if this was a network deactivation problem the same problem would appear in the case when i deactivate the wifi and after that i reactivate it. But this doesn't happen in this case. My guess is that when the problem appears the cancelPotentialWork is being called and it returns false. This means that the imageview has a reference to a task from the previous section. How can i clean all the previous references? Did you succeed to recreate the problem?Ginzburg

© 2022 - 2024 — McMap. All rights reserved.