google-cloud-messagingandroid-8.0-oreoforegroundforeground-servicegcmlistenerservice

Should we handle InstanceIDListenerService when app is in background?


Should we also handle the case when service is not in foreground? I.e., should we call startForeground (for Oreo) inside the InstanceIDListenerService by ourself? Or it is ensured that the service must be started when app is in foreground only?

To elaborate more, if refreshing token happens while app is in background (killed), then how do I handle it? Should I check if token is refreshed every time app launches?

p.s. I am implementing GCM currently, would switch to FCM early 2019 due to reasons I cannot control.


Solution

  • In my opinion, we don't have to handle the background case, since it is not mentioned in google's official documentary when implementing GCM.