0

It was working fine up to Oreo but after the API 28 PIE VERSION released the background service is not working properly, the exact flow is after starting the service without stopping it manually, the service automatically is being stopped when the app is killed. Can anyone tell me how to do it.

  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 Answers1

1

Many android device manufacturers are using aggressive policies to save battery. When a user clears his/her app from recent tabs, the app is force closed, thus cancelling all alarms,broadcastReceivers,services etc. This happens in most of the device manufacturers like OnePlus,Huwaei, Xiaomi, Vivo, Oppo etc.

They have AutoStartManagers/AutoLaunchManagers that prevent the background running of the apps. You will have to white list your app using steps mentioned in THIS SO ANSWER.

Also visit https://dontkillmyapp.com/ to know about task killers in different device manufacturers.

ankuranurag2
  • 2,300
  • 15
  • 30