onMessageCanceled
Callback invoked when a user dismisses or swipes away a notification.
Override this method to handle notification dismissal events. This is useful for tracking user engagement, cleaning up notification state, or updating notification counters. The callback is triggered when the user explicitly dismisses a notification from the notification center (not when it expires or is cleared programmatically). Example:
protected void onMessageCanceled(PushMessage message) {
// Track dismissal in analytics
String campaignId = message.getCustomData().getString("campaign_id");
Analytics.track("notification_dismissed", campaignId);
// Update badge count
SharedPreferences prefs = getApplicationContext()
.getSharedPreferences("notifications", Context.MODE_PRIVATE);
int badgeCount = prefs.getInt("badge_count", 0);
if (badgeCount > 0) {
prefs.edit().putInt("badge_count", badgeCount - 1).apply();
}
// Clean up related local data
String notificationId = message.getCustomData().getString("notification_id");
deleteNotificationData(notificationId);
}
Content copied to clipboard
Parameters
message
the push message that was dismissed by the user