Я запускаю этот диспетчер сигналов тревоги с помощью службы. Итак, я хочу остановить диспетчер будильников через 30 минут, так как он повторяется через 10 минут. Отмена не работает в моем случае пожалуйста помоги.
AlarmManager alarmMgr0 = (AlarmManager)
getSystemService(Context.ALARM_SERVICE);
Intent intent0 = new Intent(getApplicationContext(),
schedule.class);
PendingIntent pendingIntent0 =
PendingIntent.getBroadcast(getApplicationContext(), 0, intent0, 0);
Log.e(TAG, "SiteIN called");
// Intent intent0 = new Intent(this, OldEntryRemover.class);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE,26);
calendar.set(Calendar.SECOND, 0);
if (Calendar.getInstance().after(calendar)){
// Move to tomorrow
calendar.add(Calendar.DATE, 1);
}
//set that timer as a RTC Wakeup to alarm manager object
// alarmMgr0.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent0);
alarmMgr0.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
10000 * 60, pendingIntent0);
try {
thread.sleep(30000 * 60);
} catch (InterruptedException e) {
e.printStackTrace();
}
alarmMgr0.cancel(pendingIntent0);
Я предполагаю, что вам просто нужно вызвать alarmMgr0.cancel (Intent0) в зависимости от некоторой бизнес-логики (через 30 минут)
u пожалуйста, добавьте сюда конкретный код отмены детали. @ A
@ Дэн, я использовал это, но это не сработало
@immadNaseem - Мне нужно увидеть вашу логику отмены, чтобы направить вас дальше
@Dan Я обновил код. Проверить в конце
Значит, вы ждете 30 минут, а затем полностью отключите будильник? Можете ли вы предоставить трассировку стека любых ошибок? Он просто не отменяется и не возникает никаких ошибок?




Я бы посмотрел на API и посмотрел, действительно ли это то, что вам нужно.
Schedule a repeating alarm. Note: for timing operations (ticks, timeouts, etc) it is easier and much more efficient to use Handler. If there is already an alarm scheduled for the same IntentSender, it will first be canceled.
Like set(int, long, PendingIntent), except you can also supply a period at which the alarm will automatically repeat. This alarm continues repeating until explicitly removed with cancel(AlarmManager.OnAlarmListener). If the stated trigger time is in the past, the alarm will be triggered immediately, with an alarm count depending on how far in the past the trigger time is relative to the repeat interval.
If an alarm is delayed (by system sleep, for example, for non _WAKEUP alarm types), a skipped repeat will be delivered as soon as possible. After that, future alarms will be delivered according to the original schedule; they do not drift over time. For example, if you have set a recurring alarm for the top of every hour but the phone was asleep from 7:45 until 8:45, an alarm will be sent as soon as the phone awakens, then the next alarm will be sent at 9:00.
If your application wants to allow the delivery times to drift in order to guarantee that at least a certain time interval always elapses between alarms, then the approach to take is to use one-time alarms, scheduling the next one yourself when handling each alarm delivery.
как вы пытались отменить в первый раз? поделитесь кодом