在未来某个时间点创建预定通知的最佳做法是什么?
我找到了一种使用 Service
的方法,它通过 AlarmManager
使用 PendingIntent
触发。在 Service
的 onCreate()
方法中,我创建了通知。这似乎有点像滥用服务来做它不应该做的事情。
是否有另一种更简单/更优雅的方法来达到同样的目的? (有问题的用例是每天提醒用户使用我的应用做某事)
最佳答案
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/