Skip to content

fix: Finishing the activity on main thread when a notification is opened #2353

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

abdulraqeeb33
Copy link

@abdulraqeeb33 abdulraqeeb33 commented Aug 22, 2025

Description

One Line Summary

Crash occurring when a notification was opened.

Details

Motivation

The below crash was happening when a notification was received and clicked to open.

       at android.os.Parcel.createException(Parcel.java:1970)
       at android.os.Parcel.readException(Parcel.java:1934)
       at android.os.Parcel.readException(Parcel.java:1884)
       at android.app.IActivityManager$Stub$Proxy.reportSizeConfigurations(IActivityManager.java:8625)
       at android.app.ActivityThread.reportSizeConfigurations(ActivityThread.java:3327)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3286)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1970)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7156)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)

Scope

The activity was finished by the background thread earlier. So even before all the internal methods of onCreate were actually complete (on main thread), the finish method would be called by the background thread causing a crash.

OPTIONAL - Other

Testing

Unit testing

Added couple of tests

  • Testing finish being called on main thread
  • Making sure processIntent is called

Manual testing

Tested opening a notification while the app was foregrounded, app build with Android Studio 2025.1.2 with a fresh install of the OneSignal example app on a emulator running Api 36.0

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.
Kapture.2025-08-22.at.12.04.09.mp4

This change is Reviewable


Copy link
Contributor

@jinliu9508 jinliu9508 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, make sure to clean up the commit messages following the Conventional Commits specification.

@abdulraqeeb33 abdulraqeeb33 force-pushed the bug/activity-record-not-found branch from 8be1787 to 37f92e7 Compare August 22, 2025 19:20
@abdulraqeeb33 abdulraqeeb33 changed the title Activity was not being closed on main thread instead background thread fix: Finishing the activity on main thread when a notification is opened Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants