android - 如何在android中创建异步通知

标签 android android-notifications

在未来某个时间点创建预定通知的最佳做法是什么?

我找到了一种使用 Service 的方法,它通过 AlarmManager 使用 PendingIntent 触发。在 ServiceonCreate() 方法中,我创建了通知。这似乎有点像滥用服务来做它不应该做的事情。

是否有另一种更简单/更优雅的方法来达到同样的目的? (有问题的用例是每天提醒用户使用我的应用做某事)

最佳答案

What is the best practice to create a scheduled notification at some point in the future?

AlarmManager

This seems a bit like abusing the service to do something it is not supposed to be doing.

嗯……为什么?

Is there another less cumbersome / more elegant method of achieving the same end?

设置闹钟总共需要 3 到 4 个 Java 语句,再加上一个用于打包到 Intent 中的任何额外语句。在 BroadcastReceiver 中处理警报以引发关于“每日提醒”的 Notification 应该是另外约 20 行代码,外加 list 中的一个条目。

关于android - 如何在android中创建异步通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5237229/

相关文章:

android - 我们可以使用其他类型的时间选择器吗?

android - FCM 在应用程序处于后台时显示重复通知

安卓通知错误

android - 布局检查器显示 ID 的位置

php - 在 list 中声明自定义 URL 架构导致在完整的操作对话框中重复应用

android - 我们可以在没有物理罗盘的情况下获得罗盘方向吗(例如使用 2 个 GPS 点?)

java - 当 TextView 为空时,应用程序停止工作。我该如何解决?

android - 我可以检测 Android 是否已从 Notification Intent/PendingIntent 中终止应用程序(任务进程)吗?

android - 通知声音打断音乐

android - 在 android 中发送推送通知