Principle:
The Android system registers registration events (intent) in the system by applications to respond to various types of messages generated by the system. The Android system provides a large number of APIS for application management. You can configure intent and permission to implement various functions.
Auto Start
<Intent-filter>
<Action Android: Name = "android. Intent. Action. boot_completed"/>
<Category Android: Name = "android. Intent. Category. Home"/>
</Intent-filter>
And permission <uses-Permission Android: Name = "android. Permission. receive_boot_completed"> </uses-Permission>.
Example:
1. Create a broadcast receiver class: [Java]
/** $ Filename: bootbroadcastreceiver. java, V $ * $ Date: 2013-6-7 $ * copyright (c) zhenghaibo, Inc. all rights reserved. * This software is made by zhenghaibo. */package njupt. ZHB. startyouself; import android. content. broadcastreceiver; import android. content. context; import android. content. intent;/** @ Author: zhenghaibo * Web: http://blog.csdn.net/nuptboyzhb * mail: zhb931706659@126.com * 2013-6-7 Nanjing, njupt, China */public class bootbroadcastreceiver extends broadcastreceiver {static final string action_boot = "android. intent. action. boot_completed "; @ override public void onreceive (context, intent) {If (intent. getaction (). equals (action_boot) {intent startintent = new intent (context, mainactivity. class); // After receiving the broadcast, jump to mainactivity startintent. addflags (intent. flag_activity_new_task); context. startactivity (startintent );}}}
2. register the broadcast receiver in the manifest. xml file and Configure permissions.
Register a broadcast receiver:
<! -- Register the system broadcast Receiver --> <receiver er Android: Name = ". bootbroadcastreceiver "> <intent-filter> <action Android: Name =" android. intent. action. boot_completed "/> <category Android: Name =" android. intent. category. home "/> </intent-filter> </Cycler>
Add permission:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
After completing the preceding steps, start a program to complete registration. The software will be automatically started the next time the phone starts up.
Extension: not only the activity can be started automatically, but also a background service can be started. You only need to modify the content in the onreceive function in the receiver!
Source code download for the project: http://download.csdn.net/detail/nuptboyzhb/5541305
Statement: it cannot be used for commercial purposes without permission!