-
Notifications
You must be signed in to change notification settings - Fork 73
4. Repeat Notification
Elvin Thudugala edited this page Jul 28, 2025
·
2 revisions
Repeating notifications are useful for recurring reminders, periodic updates, or any scenario where you need to notify users regularly. This guide covers how to implement different types of recurring notifications.
- Notifications must be scheduled (using
NotifyTime) - Proper permissions must be granted
- Consider platform-specific limitations
The plugin supports three types of recurring notifications:
Notification repeats every day at the same time.
var dailyReminder = new NotificationRequest
{
NotificationId = 100,
Title = "Daily Reminder",
Description = "This notification appears every day",
Schedule =
{
NotifyTime = DateTime.Today.AddHours(9), // 9:00 AM
RepeatType = NotificationRepeat.Daily
}
};
await LocalNotificationCenter.Current.Show(dailyReminder);Notification repeats on the same day each week at the same time.
var weeklyReminder = new NotificationRequest
{
NotificationId = 101,
Title = "Weekly Meeting",
Description = "Team sync every Monday",
Schedule =
{
NotifyTime = DateTime.Today.AddDays(
((int)DayOfWeek.Monday - (int)DateTime.Today.DayOfWeek + 7) % 7
).AddHours(10), // Next Monday at 10:00 AM
RepeatType = NotificationRepeat.Weekly
}
};
await LocalNotificationCenter.Current.Show(weeklyReminder);Notification repeats after a specified time interval.
var intervalReminder = new NotificationRequest
{
NotificationId = 102,
Title = "Periodic Update",
Description = "Checking for updates",
Schedule =
{
NotifyTime = DateTime.Now.AddMinutes(30), // First notification after 30 minutes
RepeatType = NotificationRepeat.TimeInterval,
NotifyRepeatInterval = TimeSpan.FromHours(2) // Then every 2 hours
}
};
await LocalNotificationCenter.Current.Show(intervalReminder);- TimeInterval notifications cannot have both delay and repeat
- Use Daily or Weekly repeat for more precise timing
- Background refresh may affect timing
- Battery optimization may affect timing
- Doze mode can delay notifications
- Consider using Foreground Service for critical timing
await LocalNotificationCenter.Current.Cancel(notificationId);// Cancel existing notification
await LocalNotificationCenter.Current.Cancel(notificationId);
// Create new notification with updated parameters
var updatedNotification = new NotificationRequest
{
NotificationId = notificationId,
Title = "Updated Reminder",
Description = "Modified repeating notification",
Schedule =
{
NotifyTime = newDateTime,
RepeatType = NotificationRepeat.Daily
}
};
await LocalNotificationCenter.Current.Show(updatedNotification);var pendingNotifications = await LocalNotificationCenter.Current.GetPendingNotifications();
foreach (var notification in pendingNotifications)
{
if (notification.Schedule.RepeatType != NotificationRepeat.No)
{
// Handle repeating notification
}
}-
Unique IDs
- Use different ID ranges for different types of notifications
- Keep track of notification IDs for management
-
Timing Considerations
// Bad: Might miss notifications if app is closed NotifyTime = DateTime.Now.AddMinutes(1) // Good: Use future time that won't be missed NotifyTime = DateTime.Now.AddMinutes(5)
-
Error Handling
try { await LocalNotificationCenter.Current.Show(notification); } catch (Exception ex) { // Log error and implement retry logic if needed Debug.WriteLine($"Failed to schedule notification: {ex.Message}"); }
-
Resource Management
- Limit the number of concurrent repeating notifications
- Clean up unused notifications
- Consider battery and system resource impact
Check:
- Correct RepeatType is set
- NotifyTime is in the future
- Platform-specific restrictions
- Battery optimization settings
Solutions:
- Use longer intervals (15+ minutes)
- Implement retry logic
- Consider using push notifications
- Check system clock synchronization
Recommendations:
- Use appropriate intervals (not too frequent)
- Clean up unnecessary notifications
- Monitor battery usage
- Implement user controls for frequency
var workdayReminder = new NotificationRequest
{
NotificationId = 103,
Title = "Daily Standup",
Description = "Time for team standup",
Schedule =
{
NotifyTime = GetNextWorkday().AddHours(9).AddMinutes(30), // 9:30 AM
RepeatType = NotificationRepeat.Daily
}
};
private DateTime GetNextWorkday()
{
var date = DateTime.Today;
while (date.DayOfWeek == DayOfWeek.Saturday ||
date.DayOfWeek == DayOfWeek.Sunday)
{
date = date.AddDays(1);
}
return date;
}var healthReminder = new NotificationRequest
{
NotificationId = 104,
Title = "Activity Check",
Description = "Time to move!",
Schedule =
{
NotifyTime = DateTime.Now.AddHours(1),
RepeatType = NotificationRepeat.TimeInterval,
NotifyRepeatInterval = TimeSpan.FromHours(2)
},
Android =
{
Priority = NotificationPriority.High,
ChannelId = "health_reminders"
}
};