I can\'t figure out why whenever I open my app my notification set to go off by an alarm is set off. I have it set on a calendar for only a specific day and time. Not only
You are setting the first alarm in the past.
If the trigger time you specify is in the past, the alarm triggers immediately.
You need to set the date to the next Sunday.
using (AlarmManager manager = (AlarmManager)GetSystemService(AlarmService))
using (var calendar = Calendar.Instance)
{
if (calendar.Get(CalendarField.DayOfWeek) == Calendar.Sunday)
calendar.Add(CalendarField.Date, 1);
while (calendar.Get(CalendarField.DayOfWeek) != Calendar.Sunday)
calendar.Add(CalendarField.Date, 1);
calendar.Set(CalendarField.HourOfDay, 02);
calendar.Set(CalendarField.Minute, 15);
Log.Debug("SO", $"Current date is : {Calendar.Instance.Time.ToString()}");
Log.Debug("SO", $"Alarm will fire at {calendar.Time.ToString()}");
var managerIntent = new Intent(this, typeof(MainActivity));
var pendingIntent = PendingIntent.GetBroadcast(this, 0, managerIntent, PendingIntentFlags.UpdateCurrent);
manager.SetRepeating(AlarmType.RtcWakeup, calendar.TimeInMillis, 1000 * 60 * 60 * 24 * 7, pendingIntent);
}
[SO] Current date is : Sat Aug 12 23:01:11 PDT 2017
[SO] Alarm will fire at: Sun Aug 13 02:15:11 PDT 2017