在 Android 的特定时间显示通知的最佳方式是什么?

What is best way to show notification at a certain time in Android?

我正在开发 ToDo 应用程序。一个用户可以为任何任务选择提醒日期,我的应用程序将能够在用户选择提醒的日期显示通知。我做了关于这个主题的研究。我发现我可以使用 AlarmManager、PendingIntent、WorkManager 等...但我不知道哪种方式最好。你能告诉我应该使用哪种方法吗?

为了为您的项目选择正确的解决方案,您需要考虑以下三个问题:

Can the work be deferred, or does it need to happen right away? For example, if you need to fetch some data from the network in response to the user clicking a button, that work must be done right away. However, if you want to upload your logs to the server, that work can be deferred without affecting your app’s performance or user expectations.

Is the work dependent on system conditions? You might want your job to run only when the device meets certain conditions, such as being connected to power, having internet connectivity, and so on. For example, your app might periodically need to compress its stored data. To avoid affecting the user, you would want this job to happen only when the device is charging and idle.

Does the job need to run at a precise time? A calendar app might let a user set up a reminder for an event at a specific time. The user expects to see the reminder notification at the correct time. In other cases, the app may not care precisely when the job runs. The app might have general requirements—like, "Job A must run first, then Job B, then Job C"—but it doesn't require jobs to run at a specific time.

(source)