LocalNotificationRequest
Represents a handle to a scheduled local notification that allows you to manage and cancel it.
This class is returned by scheduleLocalNotification and provides methods to control the notification's lifecycle after it has been scheduled.
Key Features:
- Cancel scheduled notifications before they are displayed
- Remove notifications that have already been displayed
- Track scheduled notifications using unique request IDs
Quick Start:
// Schedule a notification and save the request
LocalNotification notification = new LocalNotification.Builder()
.setMessage("Cart reminder")
.setDelay(3600)
.build();
LocalNotificationRequest request = Pushwoosh.getInstance()
.scheduleLocalNotification(notification);
// Save request ID for later use
int requestId = request.getRequestId();
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("reminder_request_id", requestId);
editor.apply();
// Later, cancel the notification
int savedRequestId = prefs.getInt("reminder_request_id", -1);
if (savedRequestId != -1) {
LocalNotificationRequest savedRequest = new LocalNotificationRequest(savedRequestId);
savedRequest.cancel(); // Removes from schedule and notification tray
}
Content copied to clipboard
Important Notes:
- Request IDs are unique integers assigned by the SDK
- Scheduled notifications persist across app restarts
- Use cancel to remove both scheduled and displayed notifications
- Use unschedule to only cancel scheduled notifications (doesn't remove displayed ones)