I'm not quite sure how to interpret this sentences in the GCM Client documentation:
The android.permission.WAKE_LOCK permission so the application can keep the processor from sleeping when a message is received. Optional—use only if the app wants to keep the device from sleeping.
.
If you don't hold a wake lock while transitioning the work to a service, you are effectively allowing the device to go back to sleep before the work completes. The net result is that the app might not finish processing the GCM message until some arbitrary point in the future, which is not what you want.
and
Using WakefulBroadcastReceiver is not a requirement. If you have a relatively simple app that doesn't require a service, you can intercept the GCM message in a regular BroadcastReceiver and do your processing there.
I'm not quite sure if my app needs to hold a wakelock or not (or if it requires a service). The Push Notification part is quite important to the app and it should not be delayed for more than a few minutes. Is there a chance that the BroadcastReceiver gets suspended before receiving all the data?
Is there a chance that the BroadcastReceiver gets suspended before receiving all the data?
No. You will not get control until the entire 4K-or-less payload has been downloaded and is available to you.
However, onReceive()
is called on the main application thread, and so if your work will take more than a millisecond or so, you should use WakefulBroadcastReceiver
and an IntentService
for that work. Or, if you prefer, use my WakefulIntentService
and a regular BroadcastReceiver
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With