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广播是很重要的功能.比如我们想在系统开机之后做某些事情.监控手机的电量.监控手机的网络状态等等.这些功能都须要用到广播.当然我们也能 ...
随机推荐
- ActivityLifeCycle官方demo分解
1.左右Activity生命周期的若干条款: p=330">http://1.duoinfo.sinaapp.com/? p=330 http://1.duoinfo.sinaapp. ...
- oracle中导入导出数据备份数据库
原文:oracle中导入导出数据备份数据库 数据库所在位置 将数据导出到的文件名 用户名 备份数据库 :exp c ...
- Android小应用-----画画板
public class MainActivity extends Activity { private ImageView iv; float startX = 0; float startY = ...
- 图解IntelliJ IDEA 13版本对Android SQLite数据库的支持
IntelliJ IDEA 13版本的重要构建之一是支持Android程序开发.当然对Android SQLite数据库的支持也就成为了Android开发者对IntelliJ IDEA 13版本的绝对 ...
- leetcode第23题--Swap Nodes in Pairs
Problem: Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1 ...
- Android_WebServices_介绍
本博文为子墨原创,转载请注明出处! http://blog.csdn.net/zimo2013/article/details/38036289 1.WebService的介绍 WebService为 ...
- Sql开发技巧
原文:Sql开发技巧 简介 本文主要介绍下述几个技巧: 使用Row_Number分页 事务 根据条件刷选记录的技巧 分页 主要是使用了Row_Number()这个函数.一般如下: declare @P ...
- SQL远程备份
原文:SQL远程备份 set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go -- ====================================== ...
- Android项目---HtmlParse
在解析网站上的内容的时候,总会出现很多html的标签,一般在遇到这种数据的时候,就可以用上Html 如: content.setText(Html.fromHtml("<html> ...
- 使用pager进行分页
pager jar网址:http://java2s.com/Code/Jar/t/Downloadtaglibspagejar.htm package com.binary.entity; impor ...