即使在某些设备中使用 START_STICKY 杀死应用程序后服务也不会再次启动 [英] Service not start again after kill app even use START_STICKY in some device
问题描述
在我的服务中,我已经返回 START_STICKY
以使我的 Service
在我杀死应用程序后重新启动.
我有测试,它在设备 Samsung
、Sony
、LG
上工作,但在 Xiaomi
上不起作用(服务不重新开始)
In my Service, I have return START_STICKY
to make my Service
restart again after I kill app.
I have test and it work in device Samsung
, Sony
, LG
but in Xiaomi
it not work (service not start again)
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
我该如何处理这种情况.任何帮助或建议将不胜感激?
来自 Android 文档
How can I handle this case. Any help or suggestion would be great appreciated?
From the Android docs
/**
* Constant to return from {@link #onStartCommand}: if this service's
* process is killed while it is started (after returning from
* {@link #onStartCommand}), then leave it in the started state but
* don't retain this delivered intent. Later the system will try to
* re-create the service. Because it is in the started state, it will
* guarantee to call {@link #onStartCommand} after creating the new
* service instance; if there are not any pending start commands to be
* delivered to the service, it will be called with a null intent
* object, so you must take care to check for this.
*
* <p>This mode makes sense for things that will be explicitly started
* and stopped to run for arbitrary periods of time, such as a service
* performing background music playback.
*/
public static final int START_STICKY = 1;
推荐答案
小米和 Vivo 等一些设备有一个名为自动启动"的额外权限,它允许您的应用服务在被杀死后自动重新启动.我猜你可以在小米的附加权限中找到它.
Some devices like Xiaomi and Vivo have an extra permission called "auto start" which allows your app service to be restarted automatically after being killed. You can find it in additional permissions in Xiaomi I guess.
这篇关于即使在某些设备中使用 START_STICKY 杀死应用程序后服务也不会再次启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!