Home > Mobile >  Alarm Manager Confusion
Alarm Manager Confusion

Time:10-07

I am trying to setup a Alaram below, however sometimes it fires normally and sometimes it does not and it only fires when i "open" the app. so say if alarm was schedule for 6pm, and then when i open my app at 7pm then it will fire. any ideas?

Intent intent = new Intent(AndroidApp.Context, typeof(AlarmHandler));
PendingIntent pendingIntent = PendingIntent.GetBroadcast(AndroidApp.Context, uniqueMessageId, intent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Immutable);

AlarmManager alarmManager = AndroidApp.Context.GetSystemService(Context.AlarmService) as AlarmManager;

 alarmManager.SetExactAndAllowWhileIdle(AlarmType.RtcWakeup, triggerTime, pendingIntent);

CodePudding user response:

Switching alarmManager.SetExactAndAllowWhileIdle to alarmManager.SetAlarmClock Fixed it for me. Hope it can help someone else.

Documentation: https://developer.android.com/reference/android/app/AlarmManager#setAlarmClock(android.app.AlarmManager.AlarmClockInfo, android.app.PendingIntent)

  • Related