Android Oreo killing background services and clears pending alarms, scheduled jobs after entering doze mode

只愿长相守 提交于 2019-11-27 23:39:50

You would not be able to run background services long running in Oreo as there are behaviour changes, now Oreo to optimise system memory, battery etc, it kills background service, to solve your issue you should use foreground service.

Have a look at Background execution limits https://developer.android.com/about/versions/oreo/android-8.0-changes

A suggestion from me, if you can use FCM then go for it, becasue apps like WeChat, Facebook uses it, to deliver notifications and they don't face any problem...

Hope this helps in understanding the issue....

In Doze more, the alarms do not get reset, but get deferred to a later time. You have two mainstream options here:

  1. Use either setAndAllowWhileIdle() or setExactAndAllowWhileIdle(). However, these too can fire at the maximum frequency of 1 time per 9 minutes. So you'll have to decrease the frequency at which you get location in your app.

  2. Use a foreground service by way of showing a foreground notification. Everyone does that (apps like Uber, Google Maps etc). That way, your service won't get killed, and be treated as though you have an app open.

I'm currently facing the same issue and doing the same workaraound like you do. That is, setting the Jobscheduler to a periodic job to launch my Foreground Service every 15 min in case it is getting killed for whatever reasons like a killed task. This works like a charm on pre Oreo Versions.

For Oreo the only solution I am awared of at the moment is, to allow the app to autostart in the settings. Under installed apps that is. Then it should work like pre Oreo again. What Ive heard but not tested yet, is to set the setPersisted(true) option in the Job Scheduler. Let me know if that helps

I assumed currently DOZE mode not allowed to background service so you need to find a way that DOZE mode will not affect on your app.To solve your issue you should use foreground service. or make some battery setting. Any way my better option is you should go with Firebase Cloud Messaging

I had same issue with Oppo, Vivo, Mi and etc phones, after removing from recent applications app was getting killed even services was getting killed

Solution: I had add autostart permissions like this in my application and it worked.

After resolving this issue my app was getting frozen/killed after some time running in the background due to DOZE mode

Solution: for this condition, just go to ->Settings ->Battery Option, and allow your app to run in the background, if you do this, DOZE mode wont affect on your app,

Cheers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!