-
Notifications
You must be signed in to change notification settings - Fork 33
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -73,3 +73,5 @@ jacoco.exec | |
|
|
||
| IDE | ||
| integration-tests/.idea/ | ||
| .claude/ | ||
| .mcp.json | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,12 @@ static boolean processPendingAction(Context context) { | |
| 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,20 @@ static void handlePushAction(Context context, Intent intent) { | |
| IterableLogger.e(TAG, "handlePushAction: extras == null, can't handle push action"); | ||
| return; | ||
| } | ||
|
|
||
| // Clear any previous pending action that was never processed. | ||
| // This prevents residual actions from accumulating if they were never handled | ||
| // (e.g., if the SDK was never initialized or the action handler wasn't available). | ||
| if (pendingAction != null) { | ||
| IterableLogger.d(TAG, "Clearing previous unhandled pending action"); | ||
| pendingAction = null; | ||
|
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. Is this necessary? On line 97 we are already setting the pending action to something else. Is there a place this can be used accidentally that i am missing?
Collaborator
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. not really necessary not it was just responding to your previous comment and being extra safe for avoiding future bugs 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. yeah, but i feel like this is just adding code that virtually does nothing. My comment was more regarding the pending action that would be as left over on that method, if we are just not processing it and that is the correct behavior that's fine, but if we should do something to the pending action if it was not handled that should be clear |
||
| } | ||
|
|
||
| // Initialize minimal context for push handling if SDK hasn't been fully initialized. | ||
| // This ensures custom actions can be processed even when the app is in the background | ||
| // and the SDK hasn't been initialized yet (e.g., openApp=false scenarios). | ||
| IterableApi.initializeForPush(context); | ||
|
|
||
| IterableNotificationData notificationData = new IterableNotificationData(intent.getExtras()); | ||
| String actionIdentifier = intent.getStringExtra(IterableConstants.ITERABLE_DATA_ACTION_IDENTIFIER); | ||
| IterableAction action = null; | ||
|
|
||
| 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