Is WorkerManager a realiable way to implement alarm/reminder feature in the app?

不打扰是莪最后的温柔 提交于 2019-12-21 07:36:06

问题


We notice that AlarmManagerCompat alone, isn't a reliable way to implement alarm/ reminder feature in our app, due to different AlarmManager behaviour in different version of OS. (For instance, Doze mode)

Initially, we plan to use Evernote's android-job library, to help us implement alarm/ reminder feature in our app.

However, along the way, we also notice that Google just release WorkerManager.

So far, WorkerManager works well for us, when we run some one-time background jobs (Almost immediate, with internet connectivity constraint) after the app quit.

We have plan to use WorkerManager to implement alarm/ reminder feature.

I was wondering, how reliable is WorkerManager to implement such feature? Has anyone try it out? We are targeting API 15 and above.


回答1:


WorkManager is not appropriate for anything that must fire at a specific time as jobs, including those used by WorkManager or android-job, will not fire while the device is dozing.

For exact timing, you should absolutely be using AlarmManagerCompat and specifically, setExactAndAllowWhileIdle() which fires an alarm at exactly the specified time on all API levels.

As your exact timed alarm can and will happen while the device is dozing, your app should not require network connectivity to post your alarm/reminder notification. Ideally, the information should be in the PendingIntent itself and not even need any database fetch/etc.



来源:https://stackoverflow.com/questions/50546739/is-workermanager-a-realiable-way-to-implement-alarm-reminder-feature-in-the-app

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