标签:清单 context boot 任务 cas 启动 override and bsp
package com.example.start; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class StartReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())){ System.out.println("手机开机了!!"); //开启MainActivity Intent intent2 = new Intent(context, MainActivity.class); //把MainActivity放到任务栈里 intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent2); } } }
清单文件中: <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <receiver android:name="com.example.start.StartReceiver" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
标签:清单 context boot 任务 cas 启动 override and bsp
原文地址:http://www.cnblogs.com/loaderman/p/6416076.html