When testing parse.com push notifications (sent from CloudCode on afterSave), there is something weird.
Sometimes the Android app gets the notification immediately (below 1 second), but other times, it comes after a multi-second delay.
Restarting the app seems to cause the not-yet-received notifications to appear immediately.
What could be the cause?
Could this be a bug in, for example, the parse.com service?
Is there any limit of how many notifications can be sent or received (per unit of time) ?
The problem happens both with custom BroadcastReceiver and with the default system bar notification.
Server-side javascript CloudCode:
Parse.Cloud.afterSave("Timer", function(request) {
// from https://www.parse.com/docs/js/guide#cloud-code
console.log("Before Parse.Push.send -- without alert");
var query = new Parse.Query(Parse.Installation);
// http://blog.parse.com/announcements/pushing-from-the-javascript-sdk-and-cloud-code/ :
Parse.Push.send({
where: query,
data: {
//alert: "afterSave on a Timer -- Parse.Push.send"
}
});
console.log("After Parse.Push.send -- without alert");
});
Custom broadcast receiver in Kotlin (but the problem happens also without the custom BroadcastReceiver) :
override fun onCreate(savedInstanceState: Bundle?) {
super<BaseActivity>.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
// ...
registerReceiver()
}
private fun registerReceiver() {
val intentFilter = IntentFilter()
intentFilter.addAction("com.parse.push.intent.RECEIVE")
registerReceiver(MyBroadcastReceiver(), intentFilter)
}
inner class MyBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Toast.makeText(context, "MyBroadcastReceiver 2: onReceive: "
+ context + ";" + intent, Toast.LENGTH_SHORT).show()
loadTimers()
}
}
We are using a non-paid parse.com account for now. Could that affect the timeliness of the reaction to the push notifications?
Edit: if you think, that using push notifications to trigger near-realtime item updates/sync, is not a good idea (either in general or in parse.com), that would also be a valuable answer, especially if an alternative is proposed...
At karolvrn's suggestion, here's my answer:
I don't think there's any guarantee of immediate delivery of push notifications.
https://developers.google.com/cloud-messaging/concept-options#setting-the-priority-of-a-message
I emphasized "attempts", which implies that it does not guarantee that the message will be delivered immediately.
Here's another developer's experience with reliability issues with GCM:
https://eladnava.com/google-cloud-messaging-extremely-unreliable/