Some Android devices stop the apps/service in background

693 Views Asked by At

I am working on an app in which I have to get location after every few minutes. For this purpose I have implemented background service so that my app will not be killed. It is working fine. But on some devices like Vivo/Oppo/Infinix etc, it is not working fine. For battery optimisation, these devices have different options. These devices killed the app/service if app is consuming battery continuously in the background. Is there any way to detect or avoid such options.enter image description here

One of Vivo device have options as I mentioned in the attached image. Some devices have such options in different ways. I am unable to detect such options.

1

There are 1 best solutions below

3
On

All modern versions of Android stop background services after a few minutes, unless your app is also the foreground app. You have to make a foreground service instead. Although that just makes you less likely to be killed, you still can be- there's no way to prevent it totally.