Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when I start an alarm twice?

I'm Jumping trough hoops (well, it's not that complicated ofcourse) to avoid starting an alarm twice. The basic code goes like this:

AlarmManager mgr=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(this, MyService.class);
PendingIntent pi=PendingIntent.getService(this, 0, i, 0);
mgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, pi);

Would it matter if I would actually run this code everytime my app starts? I'm not seeing any ill effects when calling this about 10 times as an overkill-experiment, but I can't find any reference as to if this is coincidence or expected behavior.

If it is not especially expected, it feels 'wrong'. It might get me in to trouble later if the behavior of the AlarmManager changes.

like image 412
Nanne Avatar asked Apr 18 '11 19:04

Nanne


People also ask

Is it better to set 1 alarm or multiple?

The answer is just one, because setting multiple alarms to wake up may actually be harmful to your health. Despite almost one-third of adults saying they hit the snooze button over and over again, as they feel deprived of sleep, this makes you feel worse.

Does setting multiple alarms make you more tired?

“Multiple alarm-wake episodes will repeatedly draw you out of the deeper, more productive stages of sleep. Your brain is actively healing and resetting during deep sleep stages and unnecessary disruption to those processes is not going to help your energy and mood in the long run.”

What happens when alarms overlap iPhone?

The alarm will silence, but the screen will show that an alarm is going off wait for the third alarm (which won't make sound) and you will see the issue. If you want to wait for the first snoozed alarm, you will see that it too will not sound because the second alarm is still on the screen “going off”.

Is it unhealthy to set alarm?

Waking up abruptly can cause higher blood pressure and heart rate. Besides increasing your blood pressure, an alarm can add to your stress levels by getting your adrenaline rushing. The solution to this health-harming problem is to instead try gradually waking up to natural light.


1 Answers

Since the cancel method for AlarmManager is fine with a 'similar' Intent to cancel the alarm, we can say that the platform recognizes the intent given the class name. Hence calling this repeatedly shouldn't be a problem since the platform will know that for such a pending intent an alarm already exists.

Here is a post that talks something similar.

like image 127
advantej Avatar answered Nov 12 '22 22:11

advantej