Skip to content

Instantly share code, notes, and snippets.

@wangerekaharun
Created January 10, 2018 09:49
Show Gist options
  • Save wangerekaharun/8214a9d6e44331b111bf2c3a9ec8216e to your computer and use it in GitHub Desktop.
Save wangerekaharun/8214a9d6e44331b111bf2c3a9ec8216e to your computer and use it in GitHub Desktop.
Schedule an alarm that repeats every 15 minutes
Intent toastIntent= new Intent(getApplicationContext(),ToastBroadcastReceiver.class);
PendingIntent toastAlarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, toastIntent,PendingIntent.FLAG_UPDATE_CURRENT);
long startTime=System.currentTimeMillis(); //alarm starts immediately
AlarmManager backupAlarmMgr=(AlarmManager)this.getSystemService(Context.ALARM_SERVICE);
backupAlarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP,startTime,AlarmManager.INTERVAL_FIFTEEN_MINUTES,toastAlarmIntent); // alarm will repeat after every 15 minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment