Android Alarm What is the difference between the four types of alarms that AlarmManager provides and when to use what?

I want to know the difference between RTC, RTC_WAKEUP, ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP .
I want to write an alarm application in which I set the alarm and close the application and wait for the alarm for the set time.
There will be several alarms. Right now I am writing for an emulator, but later I will spend on the device. In the emulator, as soon as I set the alarm and close the emulator and restart it, it will be cleared, as I found with RTC, RTC_WAKEUP and ELAPSED_REALTIME. I'm confused. Should I use ELAPSED_REALTIME_WAKEUP? I have not seen any tutorial using ELAPSED_REALTIME_WAKEUP. please explain. Thanks.

+8
android alarm
source share
5 answers

You can read this:

http://developer.android.com/reference/android/app/AlarmManager.html

You have a difference between alarms

-4
source share

ELAPSED_REALTIME

Alarm time in SystemClock.elapsedRealtime () (time since boot, including sleep mode). This signal will not wake the device; if it turns off when the device is sleeping, it will not be delivered until the next wake up of the device.

ELAPSED_REALTIME_WAKEUP

The alarm time in SystemClock.elapsedRealtime () (the time since the boot, including sleep mode), which will wake the device when it is turned off.

RTK

Alarm time in System.currentTimeMillis () (wall time in UTC). This signal will not wake the device; if it turns off when the device is sleeping, it will not be delivered until the next wake up of the device.

RTC_WAKEUP

Alarm time in System.currentTimeMillis () (wall clock time in UTC), which will wake the device when it goes off.

+18
source share

Alarm Types:

  • ELAPSED_REALTIME - Starts a pending intent after a specified period of time from the time the device boots. If the device is asleep, it works the next time the device is awake.
  • ELAPSED_REALTIME_WAKEUP - Starts a pending intent after a specified period of time from the time the device boots. He wakes up if he is sleeping.
  • RTC - Starts a pending intent at a specified time. If the device is sleeping, it will not be delivered until the next wake up of the device.
  • RTC_WAKEUP - Runs a pending intent at a specified time, waking the device if it is sleeping.
+8
source share

There are two general types of clocks for alarms: Real Time Elapsed and Real Time Clock (RTC). Elapsed real time uses "time since system boot" as a reference, and real-time clocks use UTC (wall clock). This means that the elapsed real time is suitable for setting an alarm depending on the elapsed time (for example, an alarm that sounds every 30 seconds), since it is not affected by the time zone / locale. The type of real-time clock is better suited for alarms that depend on the current locale.

Source: https://developer.android.com/training/scheduling/alarms.html

+1
source share

From the site you can get the difference between 4 constants. Below is an example of a configuration alarm.

Calendar mCalendar = Calendar.getInstance(); mCalendar.add(Calendar.SECOND, 20); Intent intent_Timer = new Intent(TimerEvents.this, AlarmReceiver.class); intent_Timer.putExtra("alarm_message", "Drax Rules!!!"); // In reality, you would want to have a static variable for the request // code instead of 192837 PendingIntent sender = PendingIntent.getBroadcast(this, 192837, intent_Timer, PendingIntent.FLAG_UPDATE_CURRENT); // Get the AlarmManager service AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, mCalendar.getTimeInMillis(), sender); 

Hope this will be helpful for you.

0
source share

All Articles