如何使用其他活动取消多个警报 [英] how to cancel multiple alarm using other activity
问题描述
在Alarm
触发位置创建注释Activity
!和Alarm
删除其他Activity
中的代码,它仅删除最后一个触发器Alarm
,表示是否已创建 3 Alarm
并且我要删除Alarm
1 它会删除,但是当Alarm
1 的时间到达时触发,而它已被删除,并且不会触发其他Alarm
2和3 ,基于静态广播ID仅触发最后一个警报,例如,警报 3 在其他活动中触发删除代码,如果它在其他活动中使用相同的挂起意图删除时如何在我的删除警报活动中使用使用触发警报的挂起意图>
Create note Activity
from where Alarm
trigger! and Alarm
delete code in other Activity
,it delete only last trigger Alarm
means if 3 Alarm
are created and I want to delete Alarm
1 it deletes but when the time of Alarm
1 reaches it trigger while it already deleted and it wont trigger other Alarm
2 and 3, on static broadcast id it trigger only last alarm for example alarm 3 trigger delete code in other activity if it delete on using same pending intent in other activity how can i use the pending intent which use trigger alarm in my delete alarm activity
AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(getApplicationContext(), AlarmReceiver.class);
String alertTitle = mTitleText.getText().toString();
intent.putExtra(getString(R.string.alert_title), alertTitle);
// broadcastCode++;
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), broadcastCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmMgr.set(AlarmManager.RTC_WAKEUP, calender.getTimeInMillis(), pendingIntent);
cv.put(mDbHelper.TIME, timeString);
cv.put(mDbHelper.DATE, dateString);
public void delete(int id)
{
db.delete( DbHelper.TABLE_NAME, DbHelper.C_ID + "="+id, null);
db.close();
Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), CreateNote.broadcastCode, intent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
}
推荐答案
使用以下代码:
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, _id, intent, 0);
AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
希望这会有所帮助.
这篇关于如何使用其他活动取消多个警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!