-
Notifications
You must be signed in to change notification settings - Fork 36
SDK-307 Fix custom actions not working in background when SDK is not initialized #975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ca023bb
dc85543
2c74702
edfc5c8
dccf1c6
86b403b
9367979
f1d329c
3563fd3
d545fcf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,12 @@ | |
| boolean handled = false; | ||
| if (pendingAction != null) { | ||
| handled = executeAction(context, pendingAction); | ||
| pendingAction = null; | ||
| // Only clear pending action if it was handled. | ||
| // This allows the action to be processed later when SDK is fully initialized | ||
| // (e.g., when customActionHandler becomes available after initialize() is called). | ||
| if (handled) { | ||
| pendingAction = null; | ||
| } | ||
| } | ||
| return handled; | ||
| } | ||
|
|
@@ -38,6 +43,13 @@ | |
| IterableLogger.e(TAG, "handlePushAction: extras == null, can't handle push action"); | ||
| return; | ||
| } | ||
|
|
||
| // Store the application context if not already set, so custom actions can be | ||
| // processed even when the SDK hasn't been fully initialized (e.g., openApp=false) | ||
| if (IterableApi.sharedInstance._applicationContext == null && context != null) { | ||
| IterableApi.sharedInstance._applicationContext = context.getApplicationContext(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we create a method for initializing it so we don't call _applicationContext directly, if something else is necessary for pushes to work we can add it there
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! I've created a new initializeForPush(Context context) method in IterableApi that encapsulates the context initialization. This method:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| IterableNotificationData notificationData = new IterableNotificationData(intent.getExtras()); | ||
| String actionIdentifier = intent.getStringExtra(IterableConstants.ITERABLE_DATA_ACTION_IDENTIFIER); | ||
| IterableAction action = null; | ||
|
|
@@ -87,7 +99,7 @@ | |
| Intent launcherIntent = IterableNotificationHelper.getMainActivityIntent(context); | ||
| launcherIntent.putExtras(intent.getExtras()); | ||
| launcherIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); | ||
| if (launcherIntent.resolveActivity(context.getPackageManager()) != null) { | ||
Check warningCode scanning / CodeQL Dereferenced variable may be null Warning
Variable
context Error loading related location Loading this Error loading related location Loading |
||
| context.startActivity(launcherIntent); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "campaignId": 5678, | ||
| "templateId": 8765, | ||
| "messageId": "background123456", | ||
| "isGhostPush": false, | ||
| "actionButtons": [ | ||
| { | ||
| "identifier": "remindMeButton", | ||
| "title": "Remind me in 15 minutes", | ||
| "openApp": false, | ||
| "action": { | ||
| "type": "snoozeReminder", | ||
| "data": "{\"delay\":15}" | ||
| } | ||
| } | ||
| ], | ||
| "defaultAction": { | ||
| "type": null | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if it does not manage to execute the action? Can't this pendingAction become residual?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I've updated the code to clear any previous unhandled pending action when a new push action comes in. This prevents residual actions from accumulating if they were never handled. The logic now clears pendingAction at the start of handlePushAction() before setting up the new action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as stated in the other comment, that should be defined by code here, if we should have a pendingAction after not being able to handle it that is fine, but i feel like if this was not handled here it won't be in the next time if nothing changes, so we can just be calling processPendingAction indefinitely with nothing changing