I'm implementing Parse push notification. I have 2 receivers. 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). 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. This is what I did,
First I created a base BroadcastReceiver
which receives the push notification from Parse. It then removes all actions from received intent and adds a custom action eg, com.myclass.PUSH
Then I used
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
Now the broadcast is ordered and i can cancel it using abortBroadcast()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.