アラームマネージャーにはすでに質問と解決策があることを知っており、たくさん検索しましたが、同じ問題に直面しています。
私の問題は、毎回一意のIDを持つ複数のアラームを追加し、同じIDを持つアラームをキャンセルすることです。追加および削除中はすべてのアラームが正常に機能していますが、不規則な間隔の後もアラームが鳴り続けます。
これがアラームを設定するための私のコードです。
AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(getApplicationContext(), AlarmSer.class);
next = myRandom.nextInt();
PendingIntent pendingIntent =
PendingIntent.getService(getApplicationContext(),next, i, 0);
am.set(AlarmManager.RTC, firstWake, pendingIntent);
alarm.values
nextとalarmReqCodeをキャンセルするためのコードは、特定のアラームで同じです。
AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(getApplicationContext(), AlarmSer.class);
alarmReqCode=Integer.parseInt(cursor.getString(cursor.getColumnIndexOrThrow(
TodoDbAdapter.ALARMCODE)));
PendingIntent pendingIntent=
PendingIntent.getService(getApplicationContext(),alarmReqCode, i, 0);
am.cancel(pendingIntent);
LogCatで私はこれを取得しています:
03-19 11:43:03.475: V/AlarmManager(21088): waitForAlarm result :4
03-19 11:43:03.480: V/AlarmManager(21088): trigger ELAPSED_REALTIME_WAKEUP or RTC_WAKEUP