-1

I'm a newbie android developer.. I have trouble keeping the background services broadcast receivers etc alive on no stock android devices.. i have tried many solutions and couldn't find one that works... Please help.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Kindly mention what solutions have you tried. – Deˣ Jun 25 '19 at 15:47
  • Since Oreo default policy is to aggressively stop all background services. If you want your service to work non-stop you need a foreground service (with sticky notification). – Pawel Jun 25 '19 at 16:03
  • @Derek i have tried white listing the app, getting the auto start permission restarting the service on onDestroy();.. The app gets killed when removed from recent apps.. I have tried keeping the app alive by moving my processing to a foreground service and excluding it from recents.. That as the only solution that worked for me soo far. – mustansir makda Jun 25 '19 at 17:29
  • @Pawel yes that's the only thing that worked but the app gets killed when the user clears the app from recent apps... But I don't think users would like an annoying stickey notification plus apps like WhatsApp seem to work without any issues – mustansir makda Jun 25 '19 at 17:32
  • @mustansirmakda that might be because manufacturers whitelist popular apps(e.g. whatsapp, messenger etc.) by default, excluding them from being killed in background. – r2rek Jun 26 '19 at 10:52
  • @r2rek tried that's not the case. – mustansir makda Jun 26 '19 at 13:23

1 Answers1

0

Unfortunately, many of Android devices will have issues with staying alive in the background due to aggressive battery-saving policies of their manufacturers. This leaves you with two options: either instruct your users how to "white-list" your app to not get killed because of battery consumptions.

See here: Don't kill my app.

Or, have it done automatically by special permission.

See here: Optimize for Doze and App Standby

You should know that there are some issues with the second option, as it does not solve the case with all of the manufacturers and also, your app might be banned from Play Store if you request it and unless the core function of the app is adversely affected.

Deˣ
  • 4,191
  • 15
  • 24
r2rek
  • 2,083
  • 13
  • 16