使用AlarmManager进行周期性任务Android
我是Android的新手。我想开发一个将每20分钟做任何事情的应用程序:如果用户在应用中,他们只会收到一条消息,否则,该应用程序将设置一个对话框,如果用户接受该对话框,则应用程序将打开用户将收到该消息。
我搜索了如何做到这一点,最终使用警报管理器,一切都很好。但是,问题是,如果使用警报管理器对这种情况有好处。如果没有,为什么?解决方案是什么?我在某个地方读到工作经理也很好。
I am new to Android. I want to develop an app that is going to do something every 20 minutes: if the user is in the app, they just get a message, else, the app will set a dialog and if the user accepts that dialog, the app will open and the user will get that message.
I have searched how to do that and ended up using alarm manager and everything went fine. However, the question is that if using alarm manager is good for this situation. If not, why? And what is the solution? I had read somewhere that work manager is also good.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Workmanager
在此类情况下,当设备Enters 打ze模式。,我已经看到,即使在白色列出了该应用程序之后(从电池优化中删除),如果设备未使用,固定的,插入的,未插入的设备,则延迟了工人的工作,直到下一个维护窗口窗口窗口,有时会延迟数小时。
可以使用AlarmManager,但文档建议
fcm 在打ze模式下考虑。
编辑:
Workmanager
绝对建议使用持续或定期的工作,这些工作不敏感,可以应用约束的组合。WorkManager
will not be useful in a case like this when device enters Doze mode.I have seen that even after white listing the app, (removing from battery optimisation), if device is left unused, stationary, unplugged, WorkManager work is delayed until the next maintenance window, sometimes hours of delays.
AlarmManager can be used but documentation recommends
FCM is another option that could be considered in doze mode.
Edit:
WorkManager
is definitely recommended for persistent onetime or periodic works which are not time sensitive, where combination of constraints can be applied.