Regardless of whether the related service or custom threads are connected at boot time?

I am working on an Android project in which I need to upload some images to a GridView. Images may be in the cache if there is no cache, and then request an Internet server. My project is to use two threads to complete a download task. One thread to read the cache and one thread to load. Thus, there are 3 threads, including the user interface. Each of them has its own message queue and uses a handler for communication.

My question is: should I use a related service in this situation? Actually, I understood the project above, and it seems like nothing bad, but the GC works very hard, which can be done from the logarithm.

Another problem is that there are multiple threads when I use DDMS to monitor threads. This is due to the fact that the same loading mechanism is used in several actions. I let the threads exit the message loop when onPause () is called, I'm sure that only two of them come to life at the same time. But I see everyone in DDMS. (By the way, why do threads still exist? I allowed thread = null;)

So, in a word, my question is: can this download task benefit from a related service?

+6
source share
1 answer

So why are you using multiple threads? You need to download the image in the background, and when it is done, display it in the user interface. It really doesn't matter for the user interface where the images appear. And using multiple threads doesn't speed things up, it just consumes more memory. Just use one background thread: first it gets into the cache, and then it loads if not.

Services are designed when you want to do something that does not require a user interface. If you need to update the user interface in real time, the service does not make much sense.

+1
source

All Articles