0

I see there is a lot of similar questions but I have my alarm info stored in a database. The reminder is cancelled inside the database by a call to deleteReminder and it looks like this

 public boolean deleteReminder(long rowId) {

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


} 

This deletes the reminder but not the alarm. I tried changing it to

public boolean deleteReminder(long rowId) {

    new ReminderManager(this).cancelReminder();


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

}

and added a cancelReminder method in my ReminderManager activity like this

public void setReminder(Long taskId, Calendar when, String spinInterval) { Log.e(TAG, spinInterval);

    long l = Long.parseLong(spinInterval);



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

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

    mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, when.getTimeInMillis(), l, pi);
}

public void cancelReminder(){

      Intent i = new Intent(mContext, OnAlarmReceiver.class);
      PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, i, PendingIntent.FLAG_ONE_SHOT);

      mAlarmManager.cancel(pi);

     }

but it didn't work.... Can you show me the correct code to make the alarm stop repeating?

4

1 回答 1

1

用于PendingIntent.FLAG_UPDATE_CURRENT对 的两个调用PendingIntent.getBroadcast()。您发布的代码在您PendingIntent.FLAG_ONE_SHOT第二次调用时使用。

于 2013-05-14T16:05:07.837 回答