Android GCM (push notification): device doesn't receive notification if application is stopped

后端 未结 3 887
北恋
北恋 2020-11-30 06:29

I use push notification (GCM) in my Android project.

According to GCM tutorial I implemented broadcast receiver and registered it in AndroidManifest.xml

3条回答
  •  星月不相逢
    2020-11-30 07:29

    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".

提交回复
热议问题