Skip to content

Instantly share code, notes, and snippets.

@funkyidol
Last active December 24, 2015 13:49
Show Gist options
  • Save funkyidol/6808240 to your computer and use it in GitHub Desktop.
Save funkyidol/6808240 to your computer and use it in GitHub Desktop.
Starting Service at specific intervals controlled using AlarmManager
Calendar cal = Calendar.getInstance();
Intent intent = new Intent(this, MyService.class);
PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0);
AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
// Start every 30 seconds
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30*1000, pintent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment