BroadcastReceiver动态广播夸类,夸界面使用
1 public class Afsfdsf extends Activity{ 2 //界面注册广播以及广播类,注销广播 3 private MeBroadcastReceiver meBroadcastReceiver; 4 public IntentFilter mFilter; 5 public class SimpleNaviActivity extends Activity{ 6 7 protected void onCreate(Bundle savedInstanceState) { 8 super.onCreate(savedInstanceState); 9 setContentView(R.layout.activity_simplenavi); 10 11 /** 12 *注册广播 13 */ 14 meBroadcastReceiver = new MeBroadcastReceiver(); 15 mFilter = new IntentFilter(); 16 mFilter.addAction("cn.zhy.xzyd"); 17 registerReceiver(meBroadcastReceiver, mFilter); 18 } 19 20 //广播类 21 22 class MeBroadcastReceiver extends BroadcastReceiver { 23 24 @Override 25 public void onReceive(Context context, Intent intent) { 26 // TODO Auto-generated method stub 27 String action = intent.getAction(); 28 if ("cn.zhy.xzyd".equals(action)) { 29 //处理的事件 30 } 31 } 32 } 33 //注销广播 34 private void unRegisterBro(){ 35 if(meBroadcastReceiver != null) 36 unregisterReceiver(meBroadcastReceiver); 37 meBroadcastReceiver = null; 38 if(mFilter != null) 39 mFilter = null; 40 } 41 } 42 //下面代码写在你发送广播的地方 43 /* 44 Intent intent = new Intent(); 45 intent .setAction("cn.zhy.xzyd");//非常重要 46 sendBroadcast(intent ); */ 47 }