The difference between alarm and a timer is that alarm is operating outside the application. Even if the application is closed, they can still be used to activate application events or actions.
public void Createalarm () {//Gets a reference to alarm manager alarmmanager Alarmmanager = (alarmmanager) getsystemservice ( Context.alarm_service);//If the device is in hibernation, set ALARM to wake the device int alarmtype = alarmmanager.elapsed_realtime_wakeup;// 10 seconds after the device is triggered long time = 10000;//Create pending intentstring alarm_action = "alarm_action" capable of broadcasting and operation; Intent intentfofire = new Inten T (alarm_action); Pendingintent alarmintent = pendingintent.getbroadcast (this, 0, Intentfofire, 0);//Set Alarmalarmmanager.set (AlarmType , time, alarmintent);}
How do I cancel?
Cancellation of Alarmmanager.cancel (alarmintent);
How do I set up duplicates?
You can use the Setrepeting or Setinexactrepeating method of the alarm managerd.