manifest中:代码中:IntentFilterintentFilter;BootCompleteReceiverbootCompleteReceiver;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);intentFilter=newIntentFilter();intentFilter.addAction("android.intent.action.BOOT_COMPLETED");bootCompleteReceiver=newBootCompleteReceiver();registerReceiver(bootCompleteReceiver,intentFilter);}都写了BootCompleteReceiverclassBootCompleteReceiverextendsBroadcastReceiver{@OverridepublicvoidonReceive(Contextcontext,Intentintent){Toast.makeText(context,"helloworld",Toast.LENGTH_SHORT).show();}}但是在manifest中可以实现开机toast,在代码中写的registerReceiver不能实现开机toast,这是为什么??
2 回答
GCT1015
TA贡献1827条经验 获得超4个赞
动态注册和静态注册的区别。manifest里的广播应该是在会在系统的全局广播列表里注册了;代码注册的,只有在app启动执行了这段注册代码后才注册。
添加回答
举报
0/150
提交
取消