//某个Activity某个按钮里发出broadcast Intent intent = new Intent("test_broadcast"); sendBroadcast(intent);
<!-- manifest的application里 --> <receiver android:name=".MyBroadcastReceicer"> <intent-filter> <action android:name="test_broadcast"></action> </intent-filter> </receiver>
?
?
?
import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.util.Log;//写一个 类接收Broadcastpublic class MyBroadcastReceicer extends BroadcastReceiver{ @Override public void onReceive(Context arg0, Intent arg1) { //接收到broadcast 总要干点什么吧 Log.d("bbbbbb", "-----------干点什么-------------"); }}
?这样一个最简单的broadcast就完成了