问题描述
我有一个提供2种服务的应用程序:
I have an app with 2 services :
MessagingService extends FirebaseMessagingService
和
InstanceIDService extends FirebaseInstanceIdService
在AndroidManifest.xml
文件中声明.问题在于,当我的应用程序进程被迫关闭自身时,服务也会被杀死.
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.
我希望他们不要被杀死.我听说过Service
类的START_STICKY
标志,但是我无法在这些服务中覆盖onStartCommand()
方法以返回此标志...
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...
推荐答案
要回答这些评论,我没有找到解决问题的任何解决方案",因为这不是问题.如果用户要关闭我的应用,则有权.
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.
由于我的onMessageReceived()
方法属于我的应用程序中的MessagingService
,因此如果用户强制关闭该应用程序,则该应用程序和该服务均不会重新启动.
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.
正如曾伟诗在评论中所说,设置强制关闭"会停止我有关应用程序(包括服务)的所有操作,因此Google Play服务会收到通知,但我的应用程序不在这里.然后,不执行onMessageReceived()
方法.但是,该服务不会通过滑动关闭"来关闭.
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.
请参见此处.
这篇关于即使应用未运行,也要处理onMessageReceived()和onTokenRefresh()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!