16

以下のようにアラームを作成しました

Intent intent = new Intent(this, Areceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(this, 1234567, intent, 0);

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, timenow, 3000, sender);

アラームを止めるボタンを作りました。onclickメソッドで私は次のコードを書きました

Intent intentstop = new Intent(this, Areceiver.class);
PendingIntent senderstop = PendingIntent.getBroadcast(this,
            0, intentstop, 0);
AlarmManager alarmManagerstop = (AlarmManager) getSystemService(ALARM_SERVICE);

alarmManagerstop.cancel(senderstop);

しかし、仕事は止まっていません。何が問題なのですか?

4

1 に答える 1

33

アラームを開始するときに、保留中のインテントにrequest_code=1234567を指定しました。しかし、それを止めようとするとき、あなたは0を使用しています。停止しようとするときにこれを使用し、機能するはずです

Intent intentstop = new Intent(this, Areceiver.class);
PendingIntent senderstop = PendingIntent.getBroadcast(this,
            1234567, intentstop, 0);
AlarmManager alarmManagerstop = (AlarmManager) getSystemService(ALARM_SERVICE);

alarmManagerstop.cancel(senderstop);
于 2011-06-22T14:49:41.577 に答える