How to Prevent Foreground Service from Stopping on Clear All from Recent Apps on MI, Redmi, Xiaomi Devices?

24 Views Asked by At

When [tag:Foreground Service] is running and User taps on Clear all from recent Apps then it is stopping the service.It's happening only in specific devices Such as MI, Redmi, Xiaomi etc.

I couldn't found the it's solution. I want to prevent the service from Stopping even if user taps clear all from recent task.

1

There are 1 best solutions below

0
Viewed On

The service can not running forever. You can suggest to user exclude your app from battery optimization and allow autostart. In such case you can use WorkManager with foreground request to do long running operations when app is not running and can be started from background (depends from other permissions like location and etc).

The other options is suggest to user hold app in recently list. Some of launcher from vendors provide feature with "hold/lock" button. So when user click clear all, app that hold have to stayed.