以下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>



关于这些ReceiverAReceiverBactionAactionB在功能上会有什么不同?

最佳答案

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);

07-26 09:31