Android Price 5_ Custom broadcast update the ListView adapter download management via broadcast

Source: Internet
Author: User

1, in processing the download management, the service runs in the background, after the download is completed to update the ListView list button, the "Download" to "open" such a feature.

Write a static inner class in activity that inherits the broadcast. Where the value of the property Text_button is the text that the button displays. Update the list data display with madapter.notifydatasetchanged ().

     Public Static classDownloadfinishreceiverextendsbroadcastreceiver{ Public Static FinalString download_receiver= "com. Downloadfinishreceiver "; @Override Public voidOnReceive (Context context, Intent Intent) {Try {                if(Intent.getaction (). Equals (Download_receiver)) {//Pass theString url = intent.getstringextra ("url");  for(Apply apply:mapplies) {if(Apply.getdownload_backup (). Equals (URL)) {Apply.settext_button (Open);                }} madapter.notifydatasetchanged (); }            } Catch(Exception e) {e.printstacktrace (); }        }    }

2. Registering and destroying the broadcast in the back-Office services service

Privatedownloadfinishreceiver Finishreceiver; Public voidonCreate () {System.out.println ("Create service"); Intentfilter Intentfilter=NewIntentfilter (Downloadfinishreceiver.download_receiver); Finishreceiver=NewDownloadfinishreceiver ();        Registerreceiver (Finishreceiver, Intentfilter); Super. OnCreate (); }     Public voidOnDestroy () {unregisterreceiver (finishreceiver); Super. OnDestroy (); }

3. Once the download is complete, send the broadcast.

New Intent (Downloadfinishreceiver.download_receiver); Intent.putextra ("url", "http://www.baidu.com/pic/ Qqq.png "); Sendbroadcast (intent) ;

Android Price 5_ Custom broadcast update the ListView adapter download management via broadcast

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.