Android Fine number breakpoint continued to pass the pit

Source: Internet
Author: User

Android projects, it is inevitable to download some third-party applications, or their own updated packages, or download video files, you will consider the use of the method of the continuation of disconnection.



Then, there are about 3 ways to continue the power outage:

1. For example, when downloading video, call JS method, download the file, and then merge it into a file with Randomaccessfile.

2. As Xutils's breakpoint continues to pass the code, the specific self-view.

3. Use SQLite, with the randomaccessfile to achieve.


The first is mainly used to download video, why, because of network problems, such as, frequent breakpoints and continued transmission, there is a probability of a flower screen, and so on, with the latter 2 will appear this problem, and the former did not, and the disadvantage is if you do not write JS or no backstage engineer to help.

The second and third of the advantages and disadvantages of the surface can be described as xutils of the broken line can be based on the file size to determine the next start position, and the downloaded file size can be viewed in eclipse in the location of the file to see real-time growth.

The third way can be described as the size of the file from the beginning of the dead, and there will be more than one database call, regardless of synchronization problems, it is easy to get the problem of database read exception, the advantage is simple logic.


So, what are the pits?

1. Network anomalies, that is, their own manual disconnection, analog routing or WiFi interrupt situation.

Xutils and Randomaccessfile do not consider this problem, there will be a stream waiting for the network to continue to read the situation, seemingly nothing, but in fact there will be large probability of file size anomalies, pull the file out is not to parse the situation is video flower screen.

2. Frequent breakpoints (dozens of times, 10 times the probability of the following minimum).

Xutils situation is fine. However, for the project, can not use the third party package is not necessary, because the practical third-party package can not exclude the third-party package has a backdoor problem.

The use of randomaccessfile words, frequent breakpoints, there will be a small probability of abnormal events, there are 2 kinds:

1) file size exception.

2) file parsing exception. For example, the apk file, normal words can be seen in the file manager has its own logo apk, and failure will appear parsing package failure, logo for the Android logo

The workaround is simple.

is when the progress is equal to 100%, read the current APK file MD5 value, that is, according to MessageDigest to obtain and convert to MD5 value, and then the network obtained MD5 comparison.

If you open the file normally, the failure is downloaded directly.


Of course, but also to see their own specific circumstances to achieve this function, download file large, or file for video, should consider using the project embedded JS, by JS to achieve pause or continue to download the function, the project can be directly considered xutils, when the situation of network anomalies directly through the broadcast to manually control the suspension, The network continues to download this file, thus reducing the occurrence of anomalies.


Thank you!


Android Fine number breakpoint continued to pass the pit

Related Article

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.