Home » Java » Android : How to use same AlarmManager in loop?

Android : How to use same AlarmManager in loop?

Posted by: admin May 17, 2018 Leave a comment

Questions:

I write bellow method for alarm.

 public void alarm(int time){
    Intent intent = new Intent(MainActivity.this, Alarm.class);

    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), 0 , intent, 0);
    am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+time*1000, pi);
}

This method working perfectly. But the problem when I call the method more than one time. Like,

alarm(10);
alarm(50);

This time it only invoke alarm(10); But don’t invoke alarm(50);

Anyone please help why it show this problem!

Answers: