1个多小时后或应用程序处于休眠状态时,Alarmmanager不会触发服务-Android Oreo [英] Alarmmanager does not fire Service after more than 1 Hour - or when the app is in doze... - Android Oreo

查看:168
本文介绍了1个多小时后或应用程序处于休眠状态时,Alarmmanager不会触发服务-Android Oreo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Alarmmanager设置警报并启动服务五次。时间到了30分钟后,我尝试将其触发。 1小时后,2小时,3小时和5小时后-但这确实不起作用...

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...

我尝试了alarmmanager.setAlarmClock->它不起作用...
alarmmanager.setExactAndAllowWhileIdle->无法正常工作...我不知道问题出在哪里。

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

我正在使用Android 8

I am using Android 8

推荐答案

奥利奥(Oreo)发生了一些变化,例如电池电量增加等,这限制了您使用后台服务。 (看这个

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

您可以改用前台服务(带有正在进行的通知)
您必须调用 startForegroundService()而不是 startService()并在服务启动后的五秒钟内调用 startForeground(ID,YOUR_NOTIFICATION)

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

或者您可以使用 JobScheduler 使用方法)如果满足某些条件(例如,如果您已连接到互联网,设备正在充电,连接未计量等),则会触发

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)

祝您好运

这篇关于1个多小时后或应用程序处于休眠状态时,Alarmmanager不会触发服务-Android Oreo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆