Broadcast Reveiver作用
package com.paoyx;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class BroadcastActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//设置按钮
Button button = new Button(this);
button.setText("send message");
setContentView(button);
button.setOnClickListener(new OnClickListener() {
//按钮点击事件
public void onClick(View v) {
//设置intent传递数值
Intent intent = new Intent();
intent.setAction("com.paoyx.broadcast");
sendBroadcast(intent);
}
});
}
}
2个receiver代码---
package com.paoyx;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class MyReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals("com.paoyx.broadcast")) {
Log.i("log","testbroadcast");
}
}
}
package com.paoyx;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class MyReceiver2 extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals("com.paoyx.broadcast")) {
Log.i("log","testbroadcast2");
}
}
}
menifest注册监听代码---
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.paoyx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".BroadcastActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
//注册receiver,并设置优先级别,数值大的优先,所以先启动MyReceiver2
<receiver android:name=".MyReceiver">
<intent-filter android:priority="1">
<action android:name="com.paoyx.broadcast"/>
</intent-filter>
</receiver>
<receiver android:name=".MyReceiver2">
<intent-filter android:priority="2">
<action android:name="com.paoyx.broadcast"/>
</intent-filter>
</receiver>
</application>
</manifest>
Broadcast Reveiver作用的更多相关文章
- 9、四大组件之四-Broadcast Receiver
课程目标: 了解Android消息机制 掌握Broadcast发送消息的两种类型 掌握BroadcastReceiver接收消息的编程 重点难点: sendOrderedBroadcast()的理解 ...
- Angularjs中的事件广播 —全面解析$broadcast,$emit,$on
Angularjs中不同作用域之间可以通过组合使用$broadcast,$emit,$on的事件广播机制来进行通信 介绍: $broadcast的作用是将事件从父级作用域传播至子级作用域,包括自己.格 ...
- 【Android学习】Service&Boradcast初步
Service初步 掌握Service概念 掌握Service分类 Service开发能力具备 了解Service和intentService类的区别 重点难点 StartService和BoundS ...
- 【Demo 0009】Android 组件(BroadcastReceiver)
本章学习要点: 1. 了解Broadcast的作用; 2. 掌握自定义广播和系统广播的接收: 3. 掌握广播的发送:
- angularjs 控制器、作用域、广播详解
一.控制器 首先列出几种我们平常使用控制器时的几种误区: 我们知道angualrJs中一个控制器时可以对应不同的视图模板的,但这种实现方式存在的问题是: 如果视图1和视图2根本没有任何逻辑关系,这样& ...
- Practical Node.js (2018版) 第9章: 使用WebSocket建立实时程序,原生的WebSocket使用介绍,Socket.IO的基本使用介绍。
Real-Time Apps with WebSocket, Socket.IO, and DerbyJS 实时程序的使用变得越来越广泛,如传统的交易,游戏,社交,开发工具DevOps tools, ...
- 使用广播-BroadcastReceiver最详细解析
女孩:BroadcastReceiver是什么呀? 男孩:Broadcast是广播的意思,在Android中应用程序之间的传输信息的机制,BroadcastReceiver是接收广播通知的组件,广播和 ...
- Numpy基础总结
一.文件读取 numpy.genfromtxt() 可以用来读取各种文件.常用语法大致如下: numpy.genfromtxt(fname, dtype=<type 'float'>, d ...
- Android-BroadcastReceiver具体解释
什么是Broadcast Broadcast即广播,在Android广播是很重要的功能.比如我们想在系统开机之后做某些事情.监控手机的电量.监控手机的网络状态等等.这些功能都须要用到广播.当然我们也能 ...
随机推荐
- 在 CentOS 上安装 Tomcat7
1. 下载 #可以直接在官网下载然后传到服务器上,也可以直接下载#下载地址:http://tomcat.apache.org/download-70.cgi 2. 安装 # tar -xzvf apa ...
- DateTime.ToString("dd/MM/yyyy");后,不能直接Convert.ToDateTime的解决:
原文:DateTime.ToString("dd/MM/yyyy");后,不能直接Convert.ToDateTime的解决: DateTime.ToString("dd ...
- ADS-B 雷达 显示终端5.8
改动日志 1 更新背景地图. 增加了全国范围内的国际航路.区域航路信息,全部航路信息来自网络及中国民用航空局公布的公开资料:航路採用深蓝色画笔绘制航路中包括有航路代码.高度及报告点信息.代码及报告点 ...
- linux 多个源文件在编译时会产生一个目标文件
obj-m := target.o target-objs := src1.o src2.o src3.o 版权声明:本文博客原创文章.博客,未经同意,不得转载.
- 转:ShellExecute函数与ShellExecuteEx函数
ShellExecute函数 ShellExecute函数原型及參数含义例如以下: function ShellExecute(hWnd: HWND; Operation, FileName, Par ...
- POJ 3380 最大流
Paratroopers Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- 简洁vim配置方案Janus(1)
最近不想在编辑器上花太多的精力,所以找到个不错的解决方案. 在不懂vim配置的前提下也能用的很开心. 1,下载安装Janus(https://github.com/carlhuda/janus) 安装 ...
- C# 根据年、月、周、星期获得日期等
原文:C# 根据年.月.周.星期获得日期等 /// 取得某月的第一天 /// </summary> /// <param name="datetime">要 ...
- Spring IOC 之ApplicationContext的其他功能
正如上面章节所介绍的那样, org.springframework.beans.factory 包提供了管理和操作beans的 基本功能. org.springframework.context包增加 ...
- restrict
restrict是c99标准引入的,它只可以用于限定和约束指针,并表明指针是访问一个数据对象的唯一且初始的方式.即它告诉编译器,所有修改该指针所指向内存中内容的操作都必须通过该指针来修改,而不能通过其 ...