if(inta.getAction().equals("android.intent.action.BOOT_COMPLETED"))
{
/*Intent startIntent = new Intent(arg0,MainActivity.class);
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
arg0.startActivity(startIntent); */
Intent startIntent = new Intent(arg0,MQService.class);
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //启动新任务
arg0.startService(startIntent);
}
1.注册Reciever 接收Android开机消息 BootBroadcastReceiver
2.AndroidMainifest.xml中注册
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
注册Receiver接收器
<receiver android:name="com.rabbitmq.mqforward.BootBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>