为什么用START_STICKY重新启动Android服务这么慢? [英] Why so slow Android service restarting with START_STICKY?

查看:114
本文介绍了为什么用START_STICKY重新启动Android服务这么慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个后台服务,并且我正在对该服务进行所有操作.
该服务有时会处理各种活动.但是,如果应用程序关闭,该服务将以START_STICKY重新启动;否则,服务将重新启动.它可以正常工作,但有时需要很长时间才能重新启动,例如超过一分钟.

I have a background service, and I am doing all the operations on this service.
The service is working with activities at times. But if the application closes, the service restart with START_STICKY; It works correctly, but sometimes it takes a long time to restart, like more than a minute.

@Override
public void onCreate() {
    SocketIOConnect();
    super.onCreate();
}

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

如何减少重启时间?

推荐答案

如何减少重启时间?

How do I reduce restart time?

您无法控制它.操作系统将决定何时重新启动由于某种原因而终止了进程的服务.

You do not control this. It is up to the OS to determine when it will restart services whose processes were terminated for one reason or another.

请记住,如果用户强行停止了您的应用程序(例如,从设置"中),您的服务可能永远不会重启.

Bear in mind that your service might never restart, if the user force-stopped your app (e.g., from Settings).

这篇关于为什么用START_STICKY重新启动Android服务这么慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆