Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

developer.android.com/training bitmapfun project

I am using bitmapfun project (gridview) 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 backbutton 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-threadingasynctask 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?

like image 309
user2065529 Avatar asked Apr 19 '13 16:04

user2065529


1 Answers

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.

like image 121
jerry Avatar answered Nov 03 '22 15:11

jerry