Skip to content

Instantly share code, notes, and snippets.

@wangerekaharun
Created January 10, 2018 09:50
Show Gist options
  • Save wangerekaharun/6359d8e144a444842945ab4976376108 to your computer and use it in GitHub Desktop.
Save wangerekaharun/6359d8e144a444842945ab4976376108 to your computer and use it in GitHub Desktop.
Create 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