0

I need to repeat alarm every one second until 3 minutes After that automatically cancel the alarm

Here is some of the code I have been Implemented:

 Intent intent = new Intent(activity, MyReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(activity,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);

AlarmManager mAlarmManager = (AlarmManager)(activity.getSystemService( Context.ALARM_SERVICE ));
            mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),10000,pendingIntent);

I have to use cancel() method for cancellation. But I'm not sure where I have to implement this method?

Vaibhav Dhoke
  • 459
  • 6
  • 14
kavie
  • 2,154
  • 4
  • 28
  • 53

1 Answers1

0

This answer might be helpful for you. If you use Calendar, you can do it like so:

Calendar calendar = Calendar.getInstance();

To add 3 minutes to the current time before scheduling the 'cancellation' alarm, you can do:

calendar.add(Calendar.MINUTE, 3);

and then you just need to set the 'cancellation' alarm with the new time.