Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am currently stuck with my current code where after setting a reminder with AlarmManager and updating it, it shows up as two notifications instead of just one. That is just the current limitation I have as my intention with the code I had written should allow for more than one notification for different entries stored in sqlite database, but the method I am currently using is unreliable for this reason I had stated above. I have not tried anything as I am not sure how to exactly do as I had mentioned, which I had hoped for advice on how to solve this issue. I also apologize if this is not the right way to ask a question.

For example:
After adding an entry and setting a reminder 2 minutes later,
Title: Cycling
Content: Cycle at the park near the house

and then updating it to:
Title: Cycling
Content: Cycle at the park near the house for 1-2 hours

Desired Output 2 minutes later:
Title: Cycling
Content: Cycle at the park near the house for 1-2 hours

Rather than showing two notifications:
Title: Cycling
Content: Cycle at the park near the house

Title: Cycling
Content: Cycle at the park near the house for 1-2 hours

What I have tried:

In my DatabaseManager.class:
public long reminderCount(){
        SQLiteDatabase sqlDB = this.getReadableDatabase();
        return DatabaseUtils.queryNumEntries(sqlDB, DatabaseReminder.TABLE_NAME);
    }

In my AddActivity.class:
RemID = databaseManager.reminderCount()+1;
remindId = String.valueOf(RemID);                
remId = Integer.parseInt(remindId);

AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(getApplicationContext(), ReminderReceiver.class);
intent.putExtra("DateTime", dateTimePicked);
intent.putExtra("NotifID", remId);
intent.putExtra("Title", titlePicked);
intent.putExtra("Description", descriptionPicked);
PendingIntent addIntent = PendingIntent.getBroadcast(this, remId, intent, 0);
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, Date.parse(dateTimePicked), addIntent);
Posted
Updated 12-Jun-22 2:15am
v2
Comments
David Crow 8-Jun-22 8:54am    
The title of this thread asks one thing but the code snippets you've shown relate to something else. You might consider changing that if you want better help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900