Android GCM (push notification): device doesn't receive notification if application is stopped
This kind of broadcast receivers should receive messages even if my app is closed (not only if my app is in background but even if it was force stopped).
If a user force-stops your app from Settings, your code will never ever run again, until something manually runs one of your components, typically the user manually launching an activity (as of Android 3.1). Hence, if the user force-stops your app from Settings, you will not receive GCM messages on newer devices/emulators.
So, is it correct that my app can receive a message (and onReceive() method will be invoked in broadcast receiver) only if it's running or in background (but not closed)?
There is no concept of "closed" in Android from an application standpoint. If, by "closed", you mean "has no running process, where the last process was terminated normally", then yes, you should receive GCM messages and other broadcasts. But, again, force-stop is not "terminated normally".
Receive GCM notification even when the app is closed (slide/swiped away)
Closing the app by sliding it (more commonly known as swiping it away) doesn't totally kill the app. Check out this answer in Android Enthusiasts community for a more detailed description. You can see there that it is mentioned that:
..It won't directly causes services to stop..
Since listeners for GCM notifications are Service
s, this would actually mean that there is still a possibility that your app may still continue to receive them regardless if it is swiped away.
Though the result of swiping an app may also differ depending on the device it is running, one may kill/force stop it or other just as mentioned above, will stop background processes.
If the result is, however, the app is killed/force stopped, as mentioned in the answer from the link above:
For stop is a complete kill of the app -- all processes are killed, all services stopped, all notifications removed, all alarms removed, etc.
Which would result for the app to don't receive any kind of notifications at all, as it was designed for Android since version 3.1, as stated in this answer:
Apps that are in the stopped state do not receive broadcast Intents.
Stopped state is:
when the app is initially installed (before the user runs something in the app) or
after a Force Stop.
You can find more about this here: http://developer.android.com/about/versions/android-3.1.html#launchcontrols
Hope this helps clear some things somehow. Cheers! :D
Related Topics
Android Support Library Error After Updating to 23.3.0
Switching Between Fragment View
Android: How to Update a Imageview/Imagebutton with a Number to Show the Number of New Messages
Edittext Settext Not Working with Fragment
Camera in Android, How to Get Best Size, Preview Size, Picture Size, View Size, Image Distorted
Android - Getting from a Uri to an Inputstream to a Byte Array
Android Dialog, Keep Dialog Open When Button Is Pressed
Android Shape Border with Gradient
Android Webview VS Phone Browser
Android: How to Create Fade-In/Fade-Out Sound Effects for Any Music File That My App Plays
How to Align Textview Around an Imageview
Custom Fonts in Android Phonegap
Folder Added on Android Is Not Visible via Usb