使用AlarmManager进行周期性任务Android

发布于 2025-02-08 07:02:51 字数 202 浏览 3 评论 0原文

我是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最单纯的乌龟 2025-02-15 07:02:51

Workmanager在此类情况下,当设备Enters 打ze模式

Workmanager遵守节能功能和最佳实践,例如Doze Mode

,我已经看到,即使在白色列出了该应用程序之后(从电池优化中删除),如果设备未使用,固定的,插入的,未插入的设备,则延迟了工人的工作,直到下一个维护窗口窗口窗口,有时会延迟数小时。

可以使用AlarmManager,但文档建议

确切的警报仅应用于面向用户的功能。了解有关可接受的用途案例以设置精确警报的情况下, /a>


fcm 在打ze模式下考虑。

编辑:Workmanager绝对建议使用持续或定期的工作,这些工作不敏感,可以应用约束的组合。

WorkManager will not be useful in a case like this when device enters Doze mode.

WorkManager adheres to power-saving features and best practices like 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

Exact alarms should only be used for user-facing features. Learn more about the acceptable use cases for setting an exact alarm.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文