WorkerManager是在应用程序中实现警报/提醒功能的一种可行方法吗? [英] Is WorkerManager a realiable way to implement alarm/reminder feature in the app?

查看:113
本文介绍了WorkerManager是在应用程序中实现警报/提醒功能的一种可行方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们注意到,由于不同版本的OS中的AlarmManager行为不同,仅AlarmManagerCompat并不是在我们的应用中实现警报/提醒功能的可靠方法. (例如,打mode模式)

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)

最初,我们计划使用Evernote的 android-job 库,以帮助我们实现警报/应用程序中的提醒功能.

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

但是,在此过程中,我们还注意到Google刚刚发布了WorkerManager.

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

到目前为止,当我们在应用程序退出后运行一些一次性的后台作业(几乎是即时的,并且具有Internet连接限制)时,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.

我们计划使用WorkerManager来实现警报/提醒功能.

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

我想知道,WorkerManager实现这种功能的可靠性如何?有人尝试过吗?我们的目标是API 15及更高版本.

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

推荐答案

WorkManager不适合必须在特定时间触发的任何事物,因为作业(包括WorkManager或android-job使用的作业)在设备处于运行状态时不会触发打睡.

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.

对于确切的时间,您应该绝对使用AlarmManagerCompat,尤其是

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.

由于确切的定时警报可以并且将在设备打zing睡时发生,因此您的应用程序不需要网络连接即可发布警报/提醒通知.理想情况下,信息应该在PendingIntent本身中,甚至不需要任何数据库访存/等.

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.

这篇关于WorkerManager是在应用程序中实现警报/提醒功能的一种可行方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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