Alarm:
In Android, we perform all the future operations and recurring operations using Alarm.
Ex: To run a background service repeatedly with some interval, we use Alarm.
We have AlarmManager is the class in Android to work with Alarm.
Steps to create an Alarm:
1) Get Alarm manager object using the following code
AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
2) Create an Intent with the required component(service or broadcast)
Intent i = new Intent(MainActivity.this, AlarmReceiver.class);
//Here, AlarmReceiver is a BroadcastReceiver.
3) Create Pending Intent object from the above Intent
PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 231, i, FLAG_UPDATE_CURRENT);
4) Set the alarm using alarm manager. Alarm can be set for one time or repeating with some interval.
long currentTime = System.currentTimeMillis();
long repeatingInterval = 60*1000; // 1 minute
am.setRepeating(RTC_WAKEUP, currentTime, repeatingInterval, pi);
Note: Refer https://developer.android.com for more on AlarmManager.
To cancel Alarm:
if(am!=null)
am.cancel(pi);
Create an Android application to work with AlarmManager
Refer the source from