1.BroadcastReceiver的注册方式:
a.静态注册:
即在AndroidManifest.xml文件中声明;
b.动态注册:
myReceiver = new MyReceiver();
registerReceiver(myReceiver, new IntentFilter(MyReceiver.ACTION));
同时需要注销:
unregisterReceiver(myReceiver);
2.BroadcastReceiver的启动方式:
a.显式启动:
Intent mIntent = new Intent(this,MyReceiver.class);
b.隐式启动:
Intent mIntent = new Intent(MyReceiver.ACTION);
3.BroadcastReceiver的优先级:
a.如果拥有同一个<intent-filter>的并且android:priority属性没有设置任何值得两个BroadcastReceiver优先级根据其在AndroidManifest.xml文件注册的顺序为主
如:
<intent-filter>
<action android:name="com.example.dell.broadreciver.intent.action.MyReceiver"/>
</intent-filter>
b.同时也可以根据 android:priority="12"来设定优先级其中数字越大表示运行的优先级越高
如:
<intent-filter android:priority="12">
<action android:name="com.example.dell.broadreciver.intent.action.MyReceiver"/> </intent-filter>
PS:如果不想让其后面的BroadcastReceiver执行可以在他的onReceive方法中执行abortBroadcast()方法;但是发送广播的方式是:sendOrderedBroadcast(mIntent,null);