后台服务在android PIE版本中无法正常工作

时间:2019-02-05 06:48:04

标签: android android-service background-service android-9.0-pie

在Oreo上运行正常,但是在API 28 PIE VERSION发布后,后台服务无法正常运行,确切的流程是在启动服务后没有手动停止服务,当应用被终止时,服务将自动停止。谁能告诉我该怎么做。

  public void stopLocationService() {
    Log.d(TAG, "stopLocationService: ");
    Intent i = new Intent(getApplicationContext(), LocationService.class);
    stopService(i);
}

public void startLocationService() {
    Log.d(TAG, "startLocationService: ");
    Intent intent = new Intent(getApplicationContext(), LocationService.class);
    startService(intent);
}

1 个答案:

答案 0 :(得分:1)

许多android设备制造商都在使用积极的策略来节省电量。当用户从最近的标签中清除其应用程序时,应用程序将被强制关闭,从而取消所有警报,广播接收器,服务等。在大多数设备制造商(如OnePlus,Huwaei,Xiaomi,Vivo,Oppo等)中都会发生这种情况。

它们具有AutoStartManagers / AutoLaunchManagers,可以阻止应用程序在后台运行。您必须按照 THIS SO ANSWER.

中提到的步骤将您的应用列入白名单

还访问https://dontkillmyapp.com/来了解不同设备制造商的任务杀手。