/>
结果:
核心代码:
/**
* TODO:一、开机完成的广播--注册该广播(需要权限:android.permission.RECEIVE_BOOT_COMPLETED)
*
* @author hacket
*
*/
public class MyBootCompleted extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
System.out.println("开机完成。。。");
Intent intent2 = new Intent(context, MyService.class);
context.startService(intent2);
}
}
<!--TODO 二、xml中配置注册的广播 -->
<receiver android:name="cn.zengfansheng.serviceLifecycle.MyBootCompleted" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>