Java – Multithreaded download in Android

Multithreaded download in Android… here is a solution to the problem.

Multithreaded download in Android

I’ve tested some on how to speed up multiple downloads.

This table shows the speed of downloading 2 to 10 images (using the Samsung Galaxy S1) from different networks using a single thread or each download of a new thread.

        Multithread     SingleThread    
Images  Wifi    3g      Wifi    3g
   2    1,1     6,6     2,0     6,7
   4    1,7     8,0     5,2     9,6
   6    2,1     6,1     7,5     15,5
   8    2,3     7,1     10,2    20,0
   10   2,3     12,5    13,5    26,7

These results show that multithreaded downloads speed up tasks considerably.

Then I tried the same code, but on HTC Wildfire, the UI thread runs much less smoothly when the number of downloaded threads is high.

I added code that starts every low priority thread:

Thread t= new Thread{
       public void run(){

But problems remain. Is there a way for these threads not to have much impact on the UI thread? If not, how can I detect and adjust the number of threads to suit the device running the application?


Note: Ten images vary in size, and it doesn’t make sense to read the table by columns


In Samsung phones, for some reason, threads compete with the UI thread for resources. Try setting the thread priority to background … This will ensure that the thread does not compete with the UI thread, and the benefit is that it works on all devices. If you look at the source code of asynctask, they set the thread priority to the above value

Related Problems and Solutions