以下BroadcastReceiver
有什么区别:ReceiverA
具有一个意图过滤器,具有两个动作
<receiver android:name="com.example.somepackage.ReceiverA">
<intent-filter>
<action android:name="com.example.somepackage.intent.actionA"/>
<action android:name="com.example.somepackage.intent.actionB"/>
</intent-filter>
</receiver>
ReceiverB
,带有两个意图过滤器,每个动作一个<receiver android:name="com.example.somepackage.ReceiverB">
<intent-filter>
<action android:name="com.example.somepackage.intent.actionA"/>
</intent-filter>
<intent-filter>
<action android:name="com.example.somepackage.intent.actionB"/>
</intent-filter>
</receiver>
关于这些
ReceiverA
和ReceiverB
,actionA
和actionB
在功能上会有什么不同? 最佳答案
AFAIK在功能上都相同:它们被注册为收听actionA and actionB
。ReceiverA
类似于:
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(actionA);
intentFilter.addAction(actionB);
registerReceiver(ReceiverA, intentFilter);
ReceiverB
类似于:registerReceiver(ReceiverB, intentFilterActionA);
registerReceiver(ReceiverB, intentFilterActionB);