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有序广播的更多相关文章

  1. 发送有序广播Ordered Broadcast

    import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.vi ...

  2. 17_Android中Broadcast详解(有序广播,无序广播)最终广播,Bundle传递参数,传递参数的时候指定权限

     1  Broadcast是Android中的四大组件之一,他的用途很大,比如系统的一些广播:电量低.开机.锁屏等一些操作都会发送一个广播. 2  广播被分为两种不同的类型:"普通广播( ...

  3. Android学习笔记(十二)BroadcastReceiver的有序广播和优先级

    前两篇博文中简单整理了普通广播,其实还有有序广播,有序广播在开发中也是比不可少的,可以给广播接收者设定优先级来控制接受顺序,并却可以中断广播传递等等. 一.两种Broadcast: · 普通广播(No ...

  4. Zab: A simple totally ordered broadcast protocol(译)

    摘要 这是一个关于ZooKeeper正在使用的全序广播协议(Zab)的简短概述.它在概念上很容易理解,也很容易实现,并且提供很高的性能.在这篇文章里,我们会呈现ZooKeeper在Zab上的需求,也会 ...

  5. Android BroadcastReceiver 发送有序广播

    普通广播(Normal Broadcast): 一,优缺点:和有序广播的优缺点相反! 二,发送广播的方法:sendBroadcast() 有序广播(Ordered Broadcast): 一,优缺点 ...

  6. Android菜鸟的成长笔记(26)——普通广播与有序广播

    BroadcastReceiver是Android系统的四大组件之一,BroadcastReceiver是一个全局的系统级监听器,它拥有自己的独立进程. 我们来写一个最简单的广播接收过程 先在mani ...

  7. BroadcastReceiver之有序广播

    有序广播可以按一定的优先级进行传播 首先进行发送广播 public void click(View v){ Intent intent = new Intent(); intent.setAction ...

  8. 在命令行中通过adb shell am broadcast发送广播通知

    通过命令行执行adb shell am broadcast发送广播通知. adb shell am broadcast 后面的参数有:[-a <ACTION>][-d <DATA_U ...

  9. android86 监听SD卡状态,勒索软件,监听应用的安装、卸载、更新,无序广播有序广播

    * 添加权限 <uses-permission android:name="android.permission.RECEIVE_SMS"/> * 4.0以后广播接收者 ...

随机推荐

  1. 1.什么是Cython

    Cython是一种编程语言,它使Python语言的C扩展像Python本身一样简单.它旨在成为Python语言的超集,为其提供高级,面向对象,功能和动态编程.它的主要功能是支持可选的静态类型声明作为语 ...

  2. 微信小程序开发入门(一)

     小程序学习入门--(一) 最近自己学习微信小程序的过程当中自己总结出来的知识点,我会不断地更新和完善! 小程序的开发工具 一台电脑 熟悉HTML.CSS.JS基本语法 开发工具: 微信web开发者工 ...

  3. nignx 502错误不能使用/的路径方式 即pathinfo

    在server中加入 include enable-php-pathinfo.conf; 引入nginx.conf下的这个文件即可. 如果是tp框架,主要隐藏index.php的入口文件,再加入下面这 ...

  4. 省赛i题/求1~n内全部数对(x,y),满足最大公约数是质数的对数

    求1~n内全部数对(x,y),gcd(x,y)=质数,的对数. 思路:用f[n]求出,含n的对数.最后用sum[n]求和. 对于gcd(x,y)=a(设x<=y,a是质数),则必有gcd(x/a ...

  5. C++字符串操作笔试题第二波

    //1.字符串替换空格:请实现一个函数,把字符串中的每一个空格替换成"%20". //比如输入"we are happy.".则输出"we%20are ...

  6. hdu1276(士兵队列训练问题) java集合水过

    点击打开链接 有人说这题属于栈或者队列,个人认为说集合应该比較准确点. Problem Description 某部队进行新兵队列训练,将新兵从一開始按顺序依次编号.并排成一行横队,训练的规则例如以下 ...

  7. linux centos下载地址

    Centos下载地址 http://r.aminglinux.com

  8. 创建ios界面的三步骤

    1.加载数据 (包括懒加载和字典转模型等) 2.搭建界面 (常见的有九宫格算法和for循环的嵌套等) 3.实现用户交互 (通常用按钮实现)

  9. MySQL用户添加和分配权限

    mysql数据库insertdelete服务器file mysql> grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口 ...

  10. eclipse01

    http://blog.csdn.net/luman1991/article/category/6354903