zoukankan      html  css  js  c++  java
  • 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 }
    
    
    
     
  • 相关阅读:
    HTTP 协议(一)之基本概念入门
    聊聊 PHP 私有组件以及如何创建自己的 PHP 组件 (转)
    组件、框架、Packagist、Composer
    laravel 资源篇
    190318 面试题记录
    Http 协议
    python中全局变量的修改
    python lamba表达式
    python 按位置关系输出矩阵元素
    python 三目运算
  • 原文地址:https://www.cnblogs.com/shiyeguiji/p/4381569.html
Copyright © 2011-2022 走看看