broadcast的使用方法

1、发送广播

使用Intent发送广告

Intent intent=new Intent();

intent.setAction("mybroadcast");

sendBroadcast(intent);

2.在xml注册广播接收者

 

<receiver android:name="mybroadcast" >
<intent-filter>
<action android:name="com.gs.My" />
</intent-filter>
</receiver>

2、接收广播

public class My extends BroadcastReceiver{

 

public void onReceive(Context context, Intent intent) {

  System.out.println("接收");

 }  

}

posted on 2014-03-25 18:23  axiaoquana  阅读(275)  评论(0)    收藏  举报

导航