How to update UI progress for Android download file

Source: Internet
Author: User

I have written several articles about downloading. In general, the following points:

1, maintenance of a download process Hashmap,key: Using MD5 to process the file, value for the downloaded task.

To prevent the download from recurring. and save the information to the database.

2, download thread task inherits from Runnable, use Randomaccessfile to guarantee to be able to download breakpoint.

3, download the use of ContentProvider Observer to notify the UI or use listener Listener notification, of course, can also be broadcast.

Anti-compilation of very many apk. and see the download module, using listener more. This interface defines the status of the download thread start, update, error, and so on.

4, how to update the UI? It must be handler.

For example, for a list of downloads, I used handler to notify ListView.adapter.notifyDataChanged.

However, the download progress is more frequent, causing the page to refresh more frequently, basically only 3 threads are running, the page will be stuck.

Can be used in the following ways

1) ListView Item's Progress, download speed and so on need to timely view, using Settag ("xxx") way to add tag, to facilitate the update.

2) If you need to update, if you receive a notification, use Listview.findtag ("XXX") to update the way. This saves memory more than notifydatachanged

The attachment is the source code to decompile an APK.

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbgvlahuxotg3/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">

How to update UI progress for Android download file

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.