Developer.android.com/training project bitmapfun

I am using bitmapfun ( ) in my application, and while I tested this, I found a problem. The steps to reproduce this problem are as follows:

  • Open wifi → launcher application → download images (it works great).
  • Close the application ("Back" button), disable Wi-Fi → activate the data network → restart the application (it still works fine).
  • Before uploading images, I close the application (the "Back" button) → deactivates the data network → activates Wi-Fi. After this step, when you restart the application, the images do not load.

In logcat, I see that all images are canceled in imageWorker cancelPotentialWork (), and they never start. I assume that something is happening with the previous bitmapworkerTask (responsible for the download) and there is a collision with a new task. In my application, when backbutton is pressed , I clear all caches. But this is not the cause of the problem, because I also tested the same script in the original bitmapfun, and the problem also appeared! How can I fix this problem? I also changed the multithreading project into one thread! Is there a way to clear all image links 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 greatly expand my question! Ask me something!

Edit: in order to reproduce the problem, it might be better to clear the cache every time you leave the action using the menu option. Also not sure if the problem will occur if you follow steps 1-3 once. You may need to repeat them!

Edit2 (More Help): When I run the operation without problems, logcat for the first image looks like this:

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 working with the problem, 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 cancelPotentialWork was called, doInBackground never starts? According to the sequence of code, this is the next part to be executed! Does anyone have any idea where I should look for a mistake?

+6
source share
1 answer

what happens to u is ok. Since the ImageFetcher image is loaded with OnCreate (), but canceled by deactivating the network. it does not contain an auto restart code. Therefore, if you want to restart autoload, add a code to detect changes in network status. I do not think this is sensitive. Just let the user restart it by pressing sometiong button like update button etc.

+2
source

All Articles