matdev
matdev

Reputation: 4283

How to prevent app being killed in background?

On my Huawei P20 Lite (Android 9), there is a setting Power usage details -> app launch -> "Manage automatically". With this setting enabled, I noticed that the OS sometimes kills my app when it is in background.

enter image description here

The app acts as a streaming server.

Is it possible to programmatically disable "Manage automatically" and enable the "Run in background" settings ?

EDIT: I noticed that famous app such as Deezer or Spotify don't request ignoring battery optimization and they are never killed when playing music in background. Does anyone know how they achieve that ?

Upvotes: 3

Views: 5109

Answers (1)

kostyabakay
kostyabakay

Reputation: 1689

Implement Foreground Service in your app to increase the component priority in OS to lower the odds of its killing.

Upvotes: 1

Related Questions