gpt4 book ai didi

android - 在某些设备中甚至使用 START_STICKY 后杀死应用程序后服务不会再次启动

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:01:16 26 4
gpt4 key购买 nike

在我的服务中,我已返回 START_STICKY 以使我的 Service 在我终止应用程序后再次重启。
我已经测试过,它可以在设备 SamsungSonyLG 中使用,但在 Xiaomi 中无法使用(服务不支持重新开始)

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}

我该如何处理这种情况。任何帮助或建议将不胜感激?
来自 Android 文档

/**
* 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有一个额外的权限叫做“自动启动”,它可以让你的应用程序服务在被杀死后自动重启。我想你可以在小米的附加权限中找到它。

关于android - 在某些设备中甚至使用 START_STICKY 后杀死应用程序后服务不会再次启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41627537/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com