This month received a project to write a software management app like the 360 assistant, where a problem was encountered: Multi-threaded Breakpoint Download
This, because previously did not write this aspect of the application function. So, it is inevitable to self-study. Then you pick up the cables at each ANG station and sort them out. Sharing with you can also deepen my understanding in this respect.
What is multi-threaded download?
Multi-threaded download is actually thunder, bt some download principle, through a number of threads at the same time and the server connection, then you can squeeze the higher bandwidth, the general practice is to cut the file into n blocks, each piece to a separate thread to download, the respective download is completed after the file block into a file, Program to complete the cutting and assembly of the small algorithm
What is a breakpoint continuation?
Breakpoint continuation, that is, when we download the end of the time, the exit to save the download progress, when the next time you open and continue to download the last progress continues to download, do not have to restart each download, then the principle of the continuation of the breakpoint and implementation means.
How to complete multi-threaded breakpoint continuation?
Combining the two requires the program to remember the download progress of each file block, and save the storage, when the download program starts when you need to determine whether the program has downloaded the file, and take out the individual file block record, the download progress to continue to download, here you need to master Java Multi-Threading basic knowledge, The use of handler, as well as the collection, algorithm, file operation and other basic skills, but also to solve the SQLite database synchronization problem, because it is not very how to support multi-threaded operation, control is not good often there is a library locked exception, At the same time after android2.3 can not operate directly in the activity HTTP, otherwise you will receive the system sent on the networkonmainthreadexception exception, in the UI experience must remember to use asynchronous completion.
Well, after the understanding of these and then look at the source code will be pulled knot ...
Take a look first:
--------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------
As for those parts of the code, I am not posted here, I think it is convenient to see the source code directly.
here is the source of the download URL, click to download