发送广播并且接受,发送两个广播
Intent intent = new Intent(); intent.setAction("com.wxq.CUSTOM_INTENT"); sendBroadcast(intent); intent.setAction("com.wxq.test2"); sendBroadcast(intent);
@Override public void onReceive(Context context, Intent intent) { String intentName = "com.wxq.CUSTOM_INTENT"; String intentName2 = "com.wxq.test2"; if(intent.getAction().equals(intentName)) Toast.makeText(context, intentName+"Intent Detected", Toast.LENGTH_LONG).show(); else if(intent.getAction().equals(intentName2)) Toast.makeText(context, intentName2+"Intent Detected", Toast.LENGTH_LONG).show(); }AndroidMini中
加入receiver以及过滤
<receiver android:name="MyReceiverTest" >
<intent-filter>
<action android:name="com.wxq.CUSTOM_INTENT" >
</action>
</intent-filter>
<intent-filter>
<action android:name="com.wxq.test2" >
</action>
</intent-filter>
</receiver>
原文地址:http://blog.csdn.net/xqw8922/article/details/40554083