Alarmmanager does not fire Service after more than 1 Hour - or when the app is in doze… - Android Oreo [closed]

风流意气都作罢 提交于 2019-12-14 03:25:34

问题


I try to set up an alarm with Alarmmanager and fire a service five times. I try to fire it after 30 minutes after the time is set. After 1 hour, after 2 hours, 3 hours and 5 hours - but it does not really work...

I tried alarmmanager.setAlarmClock --> it does not work... alarmmanager.setExactAndAllowWhileIdle --> does not work ... I have no idea where the problem is.

I am using Android 8


回答1:


There are changes in oreo to improse battery etc. that limits your usage of background services. (Look at this)

You can use a foreground service instead (with an ongoing notification) You have to call startForegroundService() instead of startService() and call startForeground(ID, YOUR_NOTIFICATION) in the five seconds after the service is launched

Or you can use the JobScheduler (how to use it) that fire if some conditions are met (i.e. if you are connected to internet, if your device is charging, if your connection is unmetered, etc)

Good luck




回答2:


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.

Also please have a look at: https://stackoverflow.com/a/50639788/5479863



来源:https://stackoverflow.com/questions/55529514/alarmmanager-does-not-fire-service-after-more-than-1-hour-or-when-the-app-is-i

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