码迷,mamicode.com
首页 > 其他好文 > 详细

BroadcastReceiver动态广播夸类,夸界面使用

时间:2015-03-31 19:25:01      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:


 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 }

 

 

 

BroadcastReceiver动态广播夸类,夸界面使用

标签:

原文地址:http://www.cnblogs.com/shiyeguiji/p/4381569.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!