简体   繁体   English

在Android中重新启动前景服务

[英]Restarting a Foreground Service in android

I have a service, which runs in a foreground. 我有一个在前台运行的服务。 I understand that if a Foreground service is killed by the system, it's restarted after the availability of resources. 我知道,如果前台服务被系统杀死,则在资源可用后将其重新启动。

What I want to know is, if it will be restarted, even if the Foreground Service is manually killed from 'Running Services' section of 'Settings'? 我想知道的是,即使从“设置”的“运行服务”部分中手动杀死了前台服务,它是否也会重新启动?

If you want the service to restart after being killed use this method in the service object: 如果要在终止服务后重新启动服务,请在服务对象中使用以下方法:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    handleCommand(intent);
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM