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
  }

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)

See also

Constructors

Link copied to clipboard
constructor(requestId: Int)
Creates a LocalNotificationRequest instance with the specified request ID.

Properties

Link copied to clipboard
open val requestId: Int

Functions

Link copied to clipboard
open fun cancel()
Cancels and removes the local notification associated with this request.
Link copied to clipboard
open fun unschedule()
Unschedules the local notification, preventing it from being displayed.