简体   繁体   English

Parse.com推送通知和有序广播

[英]Parse.com Push notifications and ordered broadcast

I'm implementing Parse push notification. 我正在实现解析推送通知。 I have 2 receivers. 我有2个接收器。 First one will always show notification and second one will take over notification if one particular activity is running. 如果一个特定的活动正在运行,则第一个将始终显示通知,第二个将接管通知。 One registered in manifest (priority 1) and the other is registered/unregistered dynamically (priority 2). 一个已在清单中注册(优先级1),另一个已动态注册/未注册(优先级2)。 My problem is that I cant cancel the broadcast from my dynamic receiver by calling 我的问题是我无法通过调用取消动态接收器的广播

abortBroadcast()

it throws an exception 引发异常

BroadcastReceiver trying to return result during a non-ordered broadcast

So, is there a way to make the broadcast ordered or something like that? 那么,是否有办法使广播有序进行? I really want to handle the data in my activity when it is active. 我真的想在活动中处理活动中的数据。

Ok, after 2 hrs of searching, finally solved it. 确定,经过2个小时的搜索,终于解决了。 This is what I did, 这就是我所做的

First I created a base BroadcastReceiver which receives the push notification from Parse. 首先,我创建了一个基本的BroadcastReceiver ,它从Parse接收推送通知。 It then removes all actions from received intent and adds a custom action eg, com.myclass.PUSH Then I used 然后从接收到的意图中删除所有动作,并添加一个自定义动作,例如com.myclass.PUSH

context.sendOrderedBroadcast(intent, null);

to send a new ordered broadcast using my custom action. 使用我的自定义操作发送新的有序广播。

Now I set other two receiver's (the one defined in manifest and my dynamic receiver defined in activity) action to com.myclass.PUSH 现在,我将其他两个接收者(清单中定义的一个接收者和活动中定义的动态接收者)的动作设置为com.myclass.PUSH

Now the broadcast is ordered and i can cancel it using abortBroadcast() 现在广播已定购,我可以使用abortBroadcast()取消广播

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM