pablo pablo - 1 year ago 111
Android Question

Android Repeating Notifications Fire Even After Being Deleted

I have tried to make an Android reminder but something has gone wrong; when I set a repeating notification in my app the notification keeps firing untill I uninstall the app (deleting the repeating notification does not prevent it from going off). Considering this, my reminders are deleted from the database when I delete them.

This issue is also the case with my repeating alarms.

What should I do?

here are some parts of my code:

// the delete query in database class

public boolean deleteReminder(long rowId) {

return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;

// how I delete a reminder in my main activity

public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
fillData(); // populate
return true;
return super.onContextItemSelected(item);

public class ReminderManager {

private Context mContext;
private AlarmManager mAlarmManager;

public ReminderManager(Context context) {
mContext = context;
mAlarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

public void setReminder(Long taskId, Calendar when) {

Intent i = new Intent(mContext, OnAlarmReceiver.class);
i.putExtra(RemindersDbAdapter.KEY_ROWID, (long)taskId);

PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);

mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, when.getTimeInMillis(), 60 * 1000, pi);

public class ReminderService extends WakeReminderIntentService {

public ReminderService() {

void doReminderWork(Intent intent) {
Log.d("ReminderService", "Doing work.");
Long rowId = intent.getExtras().getLong(RemindersDbAdapter.KEY_ROWID);

NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

Intent notificationIntent = new Intent(this, ReminderEditActivity.class);
notificationIntent.putExtra(RemindersDbAdapter.KEY_ROWID, rowId);

PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);

Notification note=new Notification(android.R.drawable.stat_sys_warning, getString(R.string.notify_new_task_message), System.currentTimeMillis());
note.setLatestEventInfo(this, getString(R.string.notify_new_task_title), getString(R.string.notify_new_task_message), pi);
note.defaults |= Notification.DEFAULT_SOUND;
note.flags |= Notification.FLAG_AUTO_CANCEL;

int id = (int)((long)rowId);
mgr.notify(id, note);


public class OnAlarmReceiver extends BroadcastReceiver {

private static final String TAG = ComponentInfo.class.getCanonicalName();

public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Received wake up from alarm manager.");

long rowid = intent.getExtras().getLong(RemindersDbAdapter.KEY_ROWID);


Intent i = new Intent(context, ReminderService.class);
i.putExtra(RemindersDbAdapter.KEY_ROWID, rowid);



the issue in my case is not cancelling alarms, I'm wondering why when I even delete reminders in my app they just keep going off.

Answer Source

You will have to call AlarmManager.cancel(PendingIntent) with the exact same PendingIntent when you call setRepeating in order to cancel the alarm.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download