大概的步骤如下:
1. 继承BroadcastReceiver,监听BOOT_COMPLETED广播
<receiver android:name=".WatchdogBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
2. 在onReceive回调中,启动Activity即可。
public class BootReceiver extends BroadcastReceiver {
@Override
public final void onReceive(Context context, Intent intent) {
Intent intentUpdate = new Intent();
intentUpdate.setClassName(HugeDataApp.getContext(),
SpeedometerApp.class.getName());
intentUpdate .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intentUpdate.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
HugeDataApp.getContext().startActivity(intentUpdate);
}
}