简体   繁体   English

如何将属性从BroadcastReceiver1发送到BroadcastReceiver2?

[英]How can I send property from BroadcastReceiver1 to BroadcastReceiver2?

I have one service and two BroadcastReceiver . 我有一项服务和两个BroadcastReceiver I am calling first receiver like: 我正在给第一个接收方打电话:

private static final String CALLACTION = "android.intent.action.PHONE_STATE";

final IntentFilter theCallFilter = new IntentFilter();
theCallFilter.addAction(CALLACTION);

yourCallReceiver = new CallReceiver();        
registerReceiver(yourCallReceiver, theCallFilter);

and the second one similar like first one. 第二个类似第一个。

Now I need to set data from one receiver to another. 现在,我需要将数据从一个接收器设置到另一个接收器。 I want to set Boolean property which will check if the code in first BroadcastReceiver is done something and if is it then code in second can be executed. 我想设置Boolean属性,该属性将检查第一个BroadcastReceiver的代码是否已完成某些操作,如果已完成,则可以执行第二个代码。 How can i send this property from "BroadcastReceiver1" to "BroadcastReceiver2" ? 如何将该属性从“ BroadcastReceiver1”发送到“ BroadcastReceiver2”?

If you simply using a BroadcastRecevier, you can't be sure the order the system will resolve them in. The answer here is to use ordered Broadcast instead. 如果仅使用BroadcastRecevier,则不能确定系统将解决这些问题的顺序。此处的答案是改为使用有序的Broadcast。 You can then set the result and check that result in your next receiver. 然后,您可以设置结果并在下一个接收器中检查该结果。 Here is a great post from the Google Blog http://android-developers.blogspot.com/2011/01/processing-ordered-broadcasts.html 这是Google Blog http://android-developers.blogspot.com/2011/01/processing-ordered-broadcasts.html上的一篇精彩文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 BroadcastReceiver 发送短信并检查其状态? - How can I send an SMS from a BroadcastReceiver and check its status? 如何从广播接收器发送电子邮件? - How to send email from broadcastreceiver? 我想发送值“从BroadcastReceiver到Activity” - I want to send value “from BroadcastReceiver to Activity” 如何将扫描结果从广播接收器发送到服务 - How do I send scanresults from broadcastreceiver to service 我如何发送从GCM中的broadcastReceiver获得的注册ID到主要活动 - How can i send registration id getting from GCM in broadcastReceiver to main Activity 如何将消息从BroadcastReceiver发送到活动或片段 - How to send message from BroadcastReceiver to activity or fragment 如何将数组从broadcastReceiver类发送到MainActivity - How to send an array from broadcastReceiver class to MainActivity 如何在Android中将数据从BroadcastReceiver发送到Fragment - How to send data from BroadcastReceiver to Fragment in android 如何更好地将数据从BroadcastReceiver发送到Activity? - How better send data from BroadcastReceiver to Activity? 如何从BroadcastReceiver将LocalBroadcast发送到正在运行的服务? - How to Send a LocalBroadcast to a running service from a BroadcastReceiver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM