Shiva
Shiva

Reputation: 454

How can I set multiple local notification prior 30 minutes based on db value?

I have 3 questions:

  1. I have 2 tables category and task. category table contains the following fields

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

enter image description here

and the task table contains following fields:

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

enter image description here

I have to notify the user 30 minutes before the dueDate(timestamp), in my case there will be n no of tasks for the same time so I have to show local notification for all the tasks. How can I achieve this?

  1. For both the category and task I'm having the edit and delete functionality with context option. If I update the task the local notification should change accordingly. How can I achieve this?

  2. Onclick the notification, it should redirect to the corresponding task page which is a child activity of Category(MainActivity or Parent activity). How can I achieve this?

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

Upvotes: 3

Views: 75

Answers (1)

Koustuv Ganguly
Koustuv Ganguly

Reputation: 899

  1. Run a scheduler in 1 minute interval and compare the due date for 30 minutes difference each minute.
  2. When ever it matches just create a notification with task_id (Of matched row) as notification id.
  3. Keep all the data you want to display on task page in a bundle.
  4. Put that bundle as extra in the Intent containing the activity (Task page).
  5. Keep that Intent in a Pending Intent.
  6. Attach that pendingIntent object with your notification builder like mBuilder.setContentIntent(pendingIndent).
  7. Issue the notification.

As all the task_id (Assigned as Notification_ID) are unique hence one notification will not override another notification by any chance.

Upvotes: 1

Related Questions