Android multi-thread resumable download

Source: Internet
Author: User

This month, I received a project to write an APP for software management like a 360 assistant. I encountered a problem: multi-thread breakpoint download.

This is because you have not previously written this application function. Therefore, you have to learn it by yourself. Then we collected and sorted it out on various websites. I would like to share with you some further to deepen my understanding in this regard.

What is multi-thread download?

Multi-thread download is actually thunder. Some download principles of BT are connected to the server through multiple threads at the same time, so you can squeeze a higher bandwidth, the general practice is to cut the file into N blocks, each of which is handed to a separate thread for download. After each download is complete, the file blocks are combined into one file, small algorithms for cutting and assembly in the program

What is resumable data transfer?

Resumable download: When the download process is not completed, the download progress is exited. When the next download attempt is enabled, the download continues with the previous download progress, the principles and implementation methods of resumable data transfer are as follows.

How to complete multi‑thread resumable data transfer?

To combine the two into one, the program needs to remember the download progress of each file block and save it to the database. When the download program starts, you need to determine whether the program has downloaded the file, take out the storage records of each file block, and calculate the download progress to continue the download. here you need to master the basic knowledge of java multithreading, handler usage, collection, and algorithm, file Operations and other basic skills, but also to solve the issue of sqlite Database Synchronization, because it does not support multi-threaded operations, poor control, often encounter database locking exceptions, at the same time, you cannot directly operate on http in the activity after android2.3. Otherwise, you will receive the NetworkOnMainThreadException sent by the system. In terms of the UI experience, remember to use Asynchronization.

After learning about this, let's take a look at the source code ......

Let's take a look at the following ,:


Zookeeper --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


As for some of the code, I will not post it here; I think it is convenient to directly view the source code.

Click here to download the source code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.