Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

on android 8, will the background child process get suspended when app has a service and a notification in the foreground?

Tags:

android

my app has a proxy server in a native executable written by C, it always runs in the background, let's call it httpproxy.exe. The main activity I use startForegroundService and startForeground with a persist notification to keep the app in the foreground avoid killing by system, then run the httpproxy.exe in the background.

my app works well on android 5 and older verisons, but on android 8.0, when the activity goes background after minutes, httpproxy.exe looks like getting suspended, so I have to bring my app up time after time, that's unacceptable.

I heard there are a so-called Background Execution Limits on android 8, how can I have my app normally work like before?

like image 547
tim Avatar asked Oct 16 '25 03:10

tim


1 Answers

Make sure, that your app is excluded from the Doze mode.

Checking:

PowerManager powerManager =
     (PowerManager)getActivity().getSystemService(Activity.POWER_SERVICE);

powerManager.isIgnoringBatteryOptimizations(getActivity().getPackageName());

Asking the user to white-list your app:

Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
startActivity(intent);
like image 154
artkoenig Avatar answered Oct 17 '25 18:10

artkoenig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!