Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCM push notifications on android 3.1 : disable broadcast receiver

There is the problem with android push notifications (GCM) on android 3.1 : when my app is CLOSED - broadcast receiver which should handle GCM push messages (Intents) is never called.

In lower versions of android everything works just fine. Broadcast reciever is always called (even when app is closed).

I know that from Android 3.1 there is new concept: when application is not running it is in "stopped" state: http://developer.android.com/about/versions/android-3.1.html#launchcontrols

So if you want to start "stopped" application via Intent - you should add FLAG_INCLUDE_STOPPED_PACKAGES flag to Intent.

But problem is that i can't add FLAG_INCLUDE_STOPPED_PACKAGES flag to GCM Intent because GCM Intents (i mean "com.google.android.c2dm.intent.RECEIVE" and "com.google.android.c2dm.intent.REGISTRATION") are thrown by the OS.

So my question is: how can i handle push messages (on android 3.1) from GCM via broadcast reciever in situation when application (in which broadcastreceiver is registered) is closed (is in "stopped" state) ?

like image 532
ashakirov Avatar asked Sep 06 '12 14:09

ashakirov


1 Answers

how can i handle push messages (on android 3.1) from GCM via broadcast reciever in situation when application (in which broadcastreceiver is registered) is closed (is in "stopped" state) ?

You can't. If the user force-stops your app, nothing of your app will run again (on Android 3.1+) unless invoked manually, such as the user launching one of your activities. Your objective is to give the user no reason to force-stop your app.

like image 146
CommonsWare Avatar answered Nov 07 '22 19:11

CommonsWare