0

まったく同じPendingIntentオブジェクトを持つ複数のアラームを設定していますが、それらのアラームが鳴る時間は異なります。同じIntentオブジェクトをに提供して1つのアラームをキャンセルPendingIntentし、これをに渡すとAlarmManager.cancel()、すべてのアラームがキャンセルされますか(つまり、開始時刻が異なります)、それとも他の動作を示しますか?

コードは次のとおりです。

while(size != 0)
{
    timeToSet = getNewTime(); //gets calendar object
    Intent intent = new Intent(this, MyAlarmReceiver.class);
    intent.putExtra("uniqueid", uuid);
    intent.putExtra("vibrate", myalarm.getVibrate());
    intent.putExtra("important", myalarm.getImportant());
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(),      
                                       0, intent, PendingIntent.FLAG_UPDATE_CURRENT | Intent.FILL_IN_DATA);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, timeToSet.getTimeInMillis(), 604800000, pendingIntent);

    size--;
}

したがって、Intentオブジェクトはすべてのアラームで同じですが、時間は異なります。これらのアラームをキャンセルすると、次のようになります。

Intent intent = new Intent(this, MyAlarmReceiver.class);
intent.putExtra("uniqueid", uuid);
intent.putExtra("vibrate", myalarm.getVibrate());
intent.putExtra("important", myalarm.getImportant());
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | Intent.FILL_IN_DATA);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.cancel(pendingIntent);

すべてのアラームはキャンセルされますか?それが私がやりたいことです。requestCode私はすべてで異なるものを使用することができますが、PendingIntentこれらの余分なものを維持および保存したくないので、それらすべてがキャンセルされた方が良いでしょうrequestCodes

ありがとう!

4

1 に答える 1

3

事前定義された量のアラームがある場合は、アラームごとに一意のrequestCode(の2番目のパラメーター)を設定できます。getBroadcastしかし、それがあなたのために働くかどうかはわかりません。指定しない場合、requestCodeすべてのアラームが等しいと見なされるfilterEqualsため、すべてのアラームがキャンセルされます。

于 2012-07-09T08:49:26.633 に答える