android 广播机制
来源:互联网 发布:java细粒度数据级权限 编辑:程序博客网 时间:2024/06/13 10:32
import android.app.Activity;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.Toast;public class Test extends Activity{private final String ACTION_NAME = "发送广播";private Button mBtnMsgEvent = null;protected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);//注册广播registerBoradcastReceiver();LinearLayout mLinearLayout = new LinearLayout(this);mBtnMsgEvent = new Button(this);mBtnMsgEvent.setText("发送广播");mLinearLayout.addView(mBtnMsgEvent);setContentView(mLinearLayout);mBtnMsgEvent.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {Intent mIntent = new Intent(ACTION_NAME);mIntent.putExtra("yaner", "发送广播,相当于在这里传送数据");//发送广播sendBroadcast(mIntent);}});}private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver(){@Overridepublic void onReceive(Context context, Intent intent) {String action = intent.getAction();if(action.equals(ACTION_NAME)){Toast.makeText(Test.this, "处理action名字相对应的广播", 200);}}};public void registerBoradcastReceiver(){IntentFilter myIntentFilter = new IntentFilter();myIntentFilter.addAction(ACTION_NAME);//注册广播 registerReceiver(mBroadcastReceiver, myIntentFilter);}}
广播的添加方式有两种。You can either dynamically register an instance of this class with Context.registerReceiver()
or statically publish an implementation through the <receiver>
tag in your AndroidManifest.xml
.
0 0
- [Android]Android广播机制
- android 广播机制
- Android--广播机制
- Android 广播机制
- android 广播机制
- Android 广播机制 详解
- Android广播机制
- android 广播机制
- android 广播机制
- android广播机制
- Android 中的广播机制
- Android广播机制
- android 广播机制
- Android 广播事件机制
- Android学习--广播机制
- Android的广播机制
- 图解 Android 广播机制
- Android 广播机制
- 承接各类gis项目、webgis兼职,gis毕业设计代做、gis毕业论文代写
- param隐含对象
- c++操作mysql - 查询
- 第二周作业03 -- 随机生成一个n位的二进制数(质数)对应的长质数
- 慎用位图索引
- android 广播机制
- 洗牌算法
- Linux下完全删除Oracle
- iOS 数据库开源框架FMDB的快速入门与使用
- c++操作mysql - 查询结果集
- HTTP判断文件是否下完
- unity3d关于天空变换代码下载
- 使用org.apache.tools.zip实现zip压缩和解压
- 苹果开发者账号申请