setExtras
Adds custom data to the notification that can be retrieved when the notification is opened.
This allows you to attach arbitrary key-value data to the notification, which can be used for navigation, analytics, or any custom logic when the user taps the notification.
Warning: This method merges the provided Bundle with existing notification data. If you provide keys that conflict with Pushwoosh's internal keys (like "title", "l", "b", etc.), they may override notification settings. Use custom keys to avoid conflicts. Example:
// E-commerce: Attach product information
Bundle productData = new Bundle();
productData.putString("screen", "product_detail");
productData.putInt("product_id", 12345);
productData.putString("category", "electronics");
LocalNotification productReminder = new LocalNotification.Builder()
.setMessage("Your saved item is on sale!")
.setExtras(productData)
.setDelay(3600)
.build();
// Retrieve in your Activity:
// PushMessage pushMessage = Pushwoosh.getInstance().getLaunchNotification();
// String screen = pushMessage.getCustomData().getString("screen");
// int productId = pushMessage.getCustomData().getInt("product_id");
// Fitness app: Attach workout details
Bundle workoutData = new Bundle();
workoutData.putString("workout_type", "cardio");
workoutData.putInt("duration_minutes", 30);
workoutData.putString("difficulty", "intermediate");
LocalNotification workoutReminder = new LocalNotification.Builder()
.setMessage("Time for your 30-minute cardio session!")
.setExtras(workoutData)
.setDelay(7200)
.build();
// News app: Attach article metadata
Bundle articleData = new Bundle();
articleData.putString("article_id", "news_2024_001");
articleData.putString("category", "technology");
articleData.putLong("published_timestamp", System.currentTimeMillis());
LocalNotification newsAlert = new LocalNotification.Builder()
.setMessage("Breaking: Major tech announcement")
.setExtras(articleData)
.setDelay(1800)
.build();
Content copied to clipboard
Important Notes:
- Custom data is accessible via getLaunchNotification
- Avoid using Pushwoosh internal keys: "title", "l", "b", "ci", "i", "pw_msg_tag", etc.
- Keep data size reasonable - large bundles may impact performance
- Use primitive types and Strings for best compatibility
Return
this builder instance for method chaining
Parameters
extras
Bundle containing custom key-value data