Ordered Broadcast有序广播
sendBroadcast()发生无序广播
sendOrderedBroadcast()发送有序广播
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <Button
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="发生广播" /> </LinearLayout>
MainActivity
package com.example.orderbroadcast; import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.os.Build; public class MainActivity extends Activity { private Button send;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); send=(Button)this.findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.setAction("dashu.orderedBroadcast");
intent.putExtra("msg", "发送广播");
sendOrderedBroadcast(intent, null);
}
});
}
}
MyReceiver1
package com.example.orderbroadcast; import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast; public class MyReceiver1 extends BroadcastReceiver { @Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(context, "消息内容是"+intent.getStringExtra("msg"), Toast.LENGTH_LONG);
//创建Bundle对象,并存入数据
Bundle bundle=new Bundle();
bundle.putString("frist", "第一个BroadcastReceiver消息...");
//把bundle对象放到广播中传输
setResultExtras(bundle);
//取消Broadcast的继续传播
//abortBroadcast();
} }
MyReceiver
package com.example.orderbroadcast; import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast; public class MyReceiver extends BroadcastReceiver { @Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Bundle bundle = getResultExtras(true);
String frist = bundle.getString("frist");
Toast.makeText(context, "第一个Broadcast存入的消息为:" + frist,
Toast.LENGTH_LONG).show();
} }
Mainfest.xml
<receiver android:name="com.example.orderbroadcast.MyReceiver" >
<intent-filter android:priority="10" >
<action android:name="dashu.orderedBroadcast" />
</intent-filter>
</receiver>
<receiver android:name="com.example.orderbroadcast.MyReceiver1" >
<intent-filter android:priority="20" >
<action android:name="dashu.orderedBroadcast" />
</intent-filter>
</receiver>
</application>
android:priority设置接收广播优先级,取值范围-1000 到1000
Ordered Broadcast有序广播的更多相关文章
- 发送有序广播Ordered Broadcast
import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.vi ...
- 17_Android中Broadcast详解(有序广播,无序广播)最终广播,Bundle传递参数,传递参数的时候指定权限
1 Broadcast是Android中的四大组件之一,他的用途很大,比如系统的一些广播:电量低.开机.锁屏等一些操作都会发送一个广播. 2 广播被分为两种不同的类型:"普通广播( ...
- Android学习笔记(十二)BroadcastReceiver的有序广播和优先级
前两篇博文中简单整理了普通广播,其实还有有序广播,有序广播在开发中也是比不可少的,可以给广播接收者设定优先级来控制接受顺序,并却可以中断广播传递等等. 一.两种Broadcast: · 普通广播(No ...
- Zab: A simple totally ordered broadcast protocol(译)
摘要 这是一个关于ZooKeeper正在使用的全序广播协议(Zab)的简短概述.它在概念上很容易理解,也很容易实现,并且提供很高的性能.在这篇文章里,我们会呈现ZooKeeper在Zab上的需求,也会 ...
- Android BroadcastReceiver 发送有序广播
普通广播(Normal Broadcast): 一,优缺点:和有序广播的优缺点相反! 二,发送广播的方法:sendBroadcast() 有序广播(Ordered Broadcast): 一,优缺点 ...
- Android菜鸟的成长笔记(26)——普通广播与有序广播
BroadcastReceiver是Android系统的四大组件之一,BroadcastReceiver是一个全局的系统级监听器,它拥有自己的独立进程. 我们来写一个最简单的广播接收过程 先在mani ...
- BroadcastReceiver之有序广播
有序广播可以按一定的优先级进行传播 首先进行发送广播 public void click(View v){ Intent intent = new Intent(); intent.setAction ...
- 在命令行中通过adb shell am broadcast发送广播通知
通过命令行执行adb shell am broadcast发送广播通知. adb shell am broadcast 后面的参数有:[-a <ACTION>][-d <DATA_U ...
- android86 监听SD卡状态,勒索软件,监听应用的安装、卸载、更新,无序广播有序广播
* 添加权限 <uses-permission android:name="android.permission.RECEIVE_SMS"/> * 4.0以后广播接收者 ...
随机推荐
- 通过wget下载jdk
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-co ...
- [luogu] P2354 [NOI2014]随机数生成器 (贪心)
Description Input 第1行包含5个整数,依次为 x_0,a,b,c,d ,描述小H采用的随机数生成算法所需的随机种子.第2行包含三个整数 N,M,Q ,表示小H希望生成一个1到 N×M ...
- mybatis中根据日期模糊查询
首先设置起始日期startDate和结束日期endDate,数据库中日期字段为achive_time,表名为dos_dossier<select id="getDossiers&quo ...
- C/C++ Quick Sort Algorithm
本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50255069 快速排序算法,由C.A. ...
- WINSERVER-IIS-无法启动
报错信息:无法启动计算机上的服务W3SVC 开始百度,多数教程是这样写的 修复错误 运行命令提示符 fsutil resource setautoreset true c:\ 打开运行输入 servi ...
- ASP.NET-Razor常用方法
1.使用Scripts.Render()引入脚本 @sectionScrits{ @Scripts.Render("~/bundles/jquery") } 2.使用@Html.H ...
- JAVA配置Tomcat
1.下载tomcat,我jdk是1.8的,网上查了一下,说要安装tomcat8及以上的tomcat 尝试点击,弹出, 2.配置环境 3.安装通过cmd安装 4.点击开启服务 5.输入localhost ...
- ThinkPHP5.0框架开发--第1章 Tp5.0安装
ThinkPHP5.0框架开发--第1章 Tp5.0安装 第1章 Tp5.0 安装 ======================================================== 今 ...
- Scala语言
一.Scala概述 Scala简介 Scala是一种针对JVM将函数和面向对象技术组合在一起的编程语言.所以Scala必须要有JVM才能运行,和Python一样,Scala也是可以面向对象和面向函数的 ...
- oracle 11g RAC 的一些基本概念
一.脑裂以及对策 脑裂(split-brain)是集群中的一个糟糕的情况:集群中的所有集群正在工作的时候,内部通讯被断开.这种情况下,集群被分成了几个部分,每个部分的集群软件都会尝试去接管其他节点的资 ...