Broadcast listening for Android boot and Shutdown

Source: Internet
Author: User

Broadcast listening for Android boot and Shutdown

Android boot and shutdown broadcast listening
I. Boot broadcast Listening 1. register and receive the boot broadcast in the AndroidManifest. xml file
                   
         
                          
                 
       

2. Execute what to do in BroadcastReceiver
Public class XXXBroadcastReceiver extends BroadcastReceiver {@ Override public void onReceive (Context context, Intent intent) {if (intent. getAction (). equals (Intent. ACTION_BOOT_COMPLETED) {Intent newIntent = new Intent (context, XXX); newIntent. addFlags (Intent. FLAG_ACTIVITY_NEW_TASK); // note that this flag must be added; otherwise, context will fail to be started. startActivity (newIntent );}}}

Ii. listener for shutdown broadcast 1. Register with AndroidManifest. xml file to receive shutdown Broadcast
                   
                         
                                       
                 
        



2. Execute what to do in BroadcastReceiver
Public class XXXBroadcastReceiver extends BroadcastReceiver {@ Override public void onReceive (Context context, Intent intent) {// things to be handled when shutdown }}

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.