I have class for call myService with alaram Manager. From mainActivity this is my code to set alarm manager.
Intent downloader = new Intent(context, AlarmReceiver.class);
downloader.putExtra("limit", limit.getSelectedItem().toString());
downloader.putExtra("delay",perMin.getSelectedItem().toString());
downloader.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); `pendingIntent = PendingIntent.getBroadcast(context, 0, downloader,PendingIntent.FLAG_CANCEL_CURRENT);
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
int delay = Integer.parseInt(perMin.getSelectedItem().toString());
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,10 * 1000, delay * 1000, pendingIntent);
and here my alarm receiver class public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent update = new Intent(context, IntervalService.class);
Log.i(tag, "Call service from Alaram Receiver");
context.startService(update);
}}
I know when i want to cancel alarm manager from main activity easily call alarmManager.cancel(pendingIntent) but i want to cancel alarm manager to complete my service task and after that set again like as above.
Intent
extra indicating the alarm should be cancelled. – Squonk