Handle onMessageReceived() and onTokenRefresh() even if the app is not running

微笑、不失礼 提交于 2020-01-11 09:21:55

问题


I have an app with 2 services :

MessagingService extends FirebaseMessagingService

and

InstanceIDService extends FirebaseInstanceIdService

There are declared in the AndroidManifest.xml file. The problem is that when my app's process is forced close itself, the services are also killed.

I'd like them not to be killed. I've heard about the START_STICKY flag for the Service class, but I can't override the onStartCommand() method in these services so as to return this flag...


回答1:


To answer to the comments, I didn't find any "solution" to my problem because it's not a problem. If the user wants to close my app, he has the right to.

Since my onMessageReceived() method belongs to my MessagingService in my app, if the app is force-closed by the user, neither the app nor the service will restart.

As Weishi Zeng said in the comments, the "settings force close" stops all about my app including the services, so the notification is received by the Google Play services but my app isn't here to see it. Then the onMessageReceived() method is not executed. However the service is not closed with the "swipe close".

Eventually, I didn't want to find any workaround since this would be contradicting the user choice.

See here.



来源:https://stackoverflow.com/questions/38079245/handle-onmessagereceived-and-ontokenrefresh-even-if-the-app-is-not-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!