Take the 2-minute tour ×

I have an alarm checker in my activity (Groups.java) to start a service each few seconds:

public void lookForGroups()
        int seconds = 40;

           Intent myIntent = new Intent(Groups.this, GroupsTaskAlarmChecker.class);
           pendingIntent = PendingIntent.getService(Groups.this, 0, myIntent, 0);

           AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);

           Calendar calendar = Calendar.getInstance();
           calendar.add(Calendar.SECOND, 10);
           alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), seconds * 1000, pendingIntent);


Also depending on sharedPreferences variable I start this service when I reboot device.

Is posible to "kill" or start that alarm checker depending of a value of a variable? for example to automatically or manually sync my application.

Thank you very much in advance and sorry for mi english ;)

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Not sure if I understand this...but you create an Alarm checker and want to kill it if it's already running?


should do it. According to the reference, it will cancel any alarms with a matching intent

share|improve this answer
I'm sorry for my ignorance, but how can I interact with this variable if I am in another activity?(because in activity I dont have a constructor, only onCreate, onResume etc.). Thanks! –  KTSX10 Apr 19 '13 at 21:04
Ok I got it. I can call it for another activity if I declare a static function that contains "alarmManager.cancel(pendingIntent)". Thanks again ;) –  KTSX10 Apr 19 '13 at 22:44
add comment

Your Answer


