Android AlarmManager problem with setting & resetting an alarm

后端 未结 1 1959
野性不改
野性不改 2020-12-03 04:17

I use an Alarm to fetch data from server. I like to give user the option to start and stop the alarm. This means I have to check and see if alarm is already set. I found som

相关标签:
1条回答
  • 2020-12-03 04:44

    When canceling the AlarmManager do not use a PendingIntent with a flag of FLAG_CANCEL_CURRENT. Instead, cancel the PendingIntent explicitly after canceling the alarm:

    am = (AlarmManager) getSystemService(getApplicationContext().ALARM_SERVICE);
    Intent i = new Intent(getApplicationContext(),AlarmReceiver.class);
    PendingIntent p = PendingIntent.getBroadcast(getApplicationContext(), 0, i, 0);
    am.cancel(p);
    p.cancel();
    
    0 讨论(0)
提交回复
热议问题