android - 如何根据数据库值在 30 分钟前设置多个本地通知?

标签 android android-sqlite alarmmanager android-notifications notificationmanager

我有3个问题:

  1. 我有2 个类别和任务表。 类别表包含以下字段

id(int), name(text), status(int))

enter image description here

任务表包含以下字段:

id(int), category_id(Foreign_key referenced from category table), name(text), createdDate(datetime), modifiedDate(datetime), dueDate(timestamp)

enter image description here

必须在截止日期(时间戳)前 30 分钟通知用户,在我的情况下,n 没有同一时间的任务,所以我必须显示所有任务的本地通知。我怎样才能做到这一点?

  1. 对于类别和任务,我都具有带上下文选项的编辑和删除功能。如果我更新任务,本地通知应相应更改。我怎样才能做到这一点?

  2. 点击通知,它应该重定向到相应的任务页面,这是类别(MainActivity 或父 Activity )的子 Activity 。我怎样才能做到这一点?

Note: For this app I'm using SQLite local storage. One notification should not override another notification by any chance.

最佳答案

  1. 每隔 1 分钟运行一次调度程序,并比较 截止日期 每分钟有 30 分钟的差异。
  2. 当它匹配时,只需创建一个带有 task_id(匹配行的)的通知作为 通知编号
  3. 将要在任务页面上显示的所有数据 bundle 在一起。
  4. 将该包作为额外内容放入包含 Activity (任务页面)的 Intent 中。
  5. 将该 Intent 保留在待定 Intent 中。
  6. 将 pendingIntent 对象附加到您的通知生成器,例如 mBuilder.setContentIntent(pendingIndent)
  7. 发出通知。

由于所有 task_id(分配为 Notification_ID)都是唯一的,因此一个通知不会以任何机会覆盖另一个通知。

关于android - 如何根据数据库值在 30 分钟前设置多个本地通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50247469/

相关文章:

java - Android Toast.makeText() 没有出现

java - 如何在 Proguard 中保留内部类的字段和方法(不仅是类本身)

android - 当应用程序处于后台或关闭状态时,无法将记录从 Firebase 消息服务插入 SQLite 数据库

android - SQLiteOpenHelper onCreate()/onUpgrade() 何时运行?

Android:在事务期间可以从 SQLite 数据库中抛出异常吗?

android - 如何在 View 中嵌入时间选择器

android - 从 Sqlite 设置多个警报

android - 如何在android中为低电量注册广播接收器?

android - 从 Android WebView 启动下载链接后如何自动关闭浏览器?

Android PendingIntent FLAG_NO_CREATE 不返回 null