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.
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.
“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.”
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”.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With