Android 发送有序广播
来源:互联网 发布:数据库部门英语简写 编辑:程序博客网 时间:2024/05/21 10:55
一、运行效果图
程序代码
MainActivity
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void send(View view) { Intent intent = new Intent(); //定义广播事件类型 intent.setAction("Intercept_Stitch"); // 发送广播 sendOrderedBroadcast(intent,null); }}
MyReceiveOne
ublic class MyReceiverOne extends BroadcastReceiver { public MyReceiverOne() { } @Override public void onReceive(Context context, Intent intent) { Log.i("MyBroadcaseReceiverOne","自定义广播One"); }}
MyReceiveTwo
public class MyReceiverTwo extends BroadcastReceiver { public MyReceiverTwo() { } @Override public void onReceive(Context context, Intent intent) { Log.i("MyBroadcaseReceiverTwo","自定义广播Two"); abortBroadcast();//拦截有序广播 Log.i("MyBroadcaseReceiverTwo","有序广播Two,广播被我冻结"); }}
MyreceiveThree
public class MyReceiverThree extends BroadcastReceiver { public MyReceiverThree() { } @Override public void onReceive(Context context, Intent intent) { Log.i("MyBroadcaseReceiverThree","自定义广播Three"); }}
AndroidMainfest
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.edu.bzu.broadrecedemo3"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".MyReceiverOne" android:enabled="true" android:exported="true"> <intent-filter android:priority="1000"> <action android:name="Intercept_Stitch"/> </intent-filter> </receiver> <receiver android:name=".MyReceiverTwo" android:enabled="true" android:exported="true"> <intent-filter android:priority="200"> <action android:name="Intercept_Stitch"/> </intent-filter> </receiver> <receiver android:name=".MyReceiverThree" android:enabled="true" android:exported="true"> <intent-filter android:priority="600"> <action android:name="Intercept_Stitch"/> </intent-filter> </receiver> </application></manifest>
运行结果
LogCat 广播在优先级最低的MyReceiveTwo中被终结
若优先级相同,根据注册顺序来确定接收广播的顺序
阅读全文
0 0
- Android 发送有序广播
- Android-发送有序广播
- Android 发送有序广播
- android-BroadcastReceiver 发送有序广播
- android-BroadcastReceiver 发送有序广播
- Android自定义发送有序广播
- android-BroadcastReceiver 发送有序广播
- android-BroadcastReceiver 发送有序广播
- android-BroadcastReceiver 发送有序广播
- Android-广播接收者:发送有序广播
- Android--广播接收者(发送有序广播)
- Android 广播接收者练习-发送有序广播
- android 学习笔记 发送有序的广播
- Android实现发送一条有序广播
- Android中发送有序广播案例
- Android开发之发送有序广播+拦截广播
- 广播接收者-发送有序广播
- 广播接收者---发送有序广播
- 孙正义软银帝国的新投资, 英伟达, ARM, ONEWEB
- エンティティによりデータサービスの作成及びCRUD
- Android Binder学习(三)之defaultServiceManager()的分析
- Leetcode练习<十一> 整数翻转
- 51Nod-1080 两个数的平方和【暴力法】
- Android 发送有序广播
- 离群点(孤立点、异常值)检测方法
- WSGI底层HTTP请求接口处理
- run也提示waiting for debugger
- 【Linux】启动顺序
- ObjectTypeExample 引用类型的值"对象"是引用类型的实例JavaScript
- 小练习
- Java特性多态
- 解决网站项目本地运行ok,将代码上传到服务器中或github中无CSS效果