0

I have a problem with my alarm manager.

I want execute my code every 2 minutes so i made an alarm like this :

AlarmManager manager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 120000, pendingIntent);

But when i test this, my pendingIntent is executed every minutes.

If i start the application at 15:05:30 the first start of my pending intent is at : 15:06:00 and after every minutes.

I want to start when i start the application and after every 2 minutes.

Thx for your answers :)

Sagon nicolas
  • 198
  • 3
  • 23
  • Like this ? manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.add(Calendar.SECOND, 60 * 2), 0, pendingIntent); – Sagon nicolas Sep 25 '14 at 13:23
  • ah no, the 2nd parameter is correct, just add after `Calendar calendar = Calendar.getInstance();` – Spurdow Sep 25 '14 at 13:24
  • if it wont work you can go over my answer here. http://stackoverflow.com/questions/25375968/android-execute-a-function-after-1-hour/25376339#25376339[http://stackoverflow.com/questions/25375968/android-execute-a-function-after-1-hour/25376339#25376339], just change 1 hour to 2 minutes. – Spurdow Sep 25 '14 at 13:24
  • thanks with your answer it's work very fine ;) – Sagon nicolas Sep 25 '14 at 14:54
  • did my first comment work? or the link? – Spurdow Sep 25 '14 at 15:08
  • the good thing about the second answer (the link) is that you can put condition whenever a repeating task is pre-executed. – Spurdow Sep 25 '14 at 15:11

0 Answers0