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