Is there a way to choose what apps are allowed or denied to run background services in Android 9? I know that I can kill them in Settings > Apps & notifications > 〈 app 〉 > Force stop
, but I need that
- the service is never started until I open the app;
- it is run when I open the app;
- it is killed when I close the app.
Let me make an example with WhatsApp (which is not an app I'm having problems with but makes it easier to explain what I need):
- when I boot the phone it shouldn't check for new messages
- when I open WhatsApp it should download them
- once I closed the app new messages shouldn't check for new messages until I open it again
If possible I would prefer a non-root solution.
Update
That's not a duplicate of Disable autostart on boot: I need not only to prevent autostart at boot, but also to kill all the background processes of the app when I close it.
RUN_IN_BACKGROUND
and/orRUN_ANY_IN_BACKGROUND
prevents the app to run a background service when you close it (i.e. when the app is not in foreground). If by "kill all of its processes" you mean the native processs (Virtual Machines), that's only possible using Force Stop. But that's unnecessary because cached process cannot do any background activity if restricted in Java framework. "Don't keep activities" and "Background process limit" in Developer Options are more aggressive ways to kill background app processes but they apply to all apps and never recommended. – Irfan Latif Feb 29 '20 at 18:07