activity中使用BroadcserReceiver

只要在onCreate()中注册

// 注册广播
receiver = new ShopDetailBroadcserReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("com.szx.YYY");
this.registerReceiver(receiver, intentFilter);

声明一个广播

/*
* 接收个数量改变广播
*/
public class ShopDetailBroadcserReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
  if (intent.getAction().equals("com.szx.YYY")) {
    hanlder.sendEmptyMessage(0);
  }
}

}

 

你可能感兴趣的:(Activity)