Skip to content

Android ReactActivity Destroy Prevents Successful OnActivityResult Calls #52114

Open

Description

@melissaosullivan

Description

If a native module opens an activity that redirects out of the application and the application is killed in the background by the Android OS, the react context is lost and the native module's activity is unable to call onActivityResult.

If the redirect from the third party app is back to the activity in the native module, the ReactActivity is not created at this point. When the native activity then sets result and finishes to return back to the ReactActivity the ReactActivity has to start up.

Originally reported: #30277

Steps to reproduce

Building the App

cd ReproducerApp
npm install
npm start
npm run android

Reproduction Steps

  1. Run the app on an Android device
  2. Tap the "Open Activity" button
  3. In the second activity, tap "Go to Web" to open Google in a browser
  4. Use the following command to forcibly kill the app:
    adb shell am kill com.reproducerapp
    
  5. Resume the activity with:
    adb shell am start -n com.reproducerapp/.RedirectActivity -d "redirect://crash"
    
  6. Tap "Return Result" in the activity
  7. Check logcat for missing "RESULT" and "Completed" logs

Expected Behavior

When returning to the app after it's been killed, the callback should work and you should see "RESULT" and "Completed" in the logs.

Actual Behavior

When the app is killed and then restored, the activity result is processed before React Native is ready. The JavaScript callback is not executed, and you won't see "RESULT" or "Completed" logs, indicating the callback was lost.

React Native Version

0.79.2

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info

System:
  OS: macOS 15.5
  CPU: (10) arm64 Apple M1 Max
  Memory: 268.70 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.8
    path: ~/.nvm/versions/node/v18.20.8/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.9.2
    path: ~/.nvm/versions/node/v18.20.8/bin/npm
  Watchman:
    version: 2025.04.28.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK: Not Found
  Android SDK:
    API Levels:
      - "30"
      - "31"
      - "32"
      - "33"
      - "33"
      - "34"
      - "35"
    Build Tools:
      - 28.0.3
      - 29.0.2
      - 30.0.2
      - 30.0.3
      - 33.0.1
      - 34.0.0
      - 34.0.0
      - 35.0.0
      - 35.0.0
      - 36.0.0
    System Images:
      - android-26 | Google APIs ARM 64 v8a
      - android-27 | ARM 64 v8a
      - android-27 | Google Play Intel x86 Atom
      - android-28 | ARM 64 v8a
      - android-28 | Google APIs ARM 64 v8a
      - android-28 | Google ARM64-V8a Play ARM 64 v8a
      - android-29 | Google APIs ARM 64 v8a
      - android-29 | Google Play ARM 64 v8a
      - android-30 | Google Play ARM 64 v8a
      - android-31 | Google Play ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
      - android-35 | Google APIs ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
      - android-UpsideDownCake | Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.3 AI-243.24978.46.2431.13363775
  Xcode:
    version: /undefined
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.8
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 18.0.0
    wanted: 18.0.0
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.79.2
    wanted: 0.79.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

info React Native v0.80.0 is now available (your project is running on v0.79.2).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.80.0
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.79.2&to=0.80.0
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".

Stacktrace or Logs

unknown:ReactHost com.reproducerapp E  Unhandled SoftException (Ask Gemini)
                                        com.facebook.react.bridge.ReactNoCrashSoftException: raiseSoftException(onActivityResult(activity = "com.reproducerapp.MainActivity@1afbd28", requestCode = "100", resultCode = "-1", data = "Intent { (has extras) }")): Tried to access onActivityResult while context is not ready
                                        	at com.facebook.react.runtime.ReactHostImpl.raiseSoftException(ReactHostImpl.java:1025)
                                        	at com.facebook.react.runtime.ReactHostImpl.raiseSoftException(ReactHostImpl.java:1018)
                                        	at com.facebook.react.runtime.ReactHostImpl.onActivityResult(ReactHostImpl.java:776)
                                        	at com.facebook.react.ReactDelegate.onActivityResult(ReactDelegate.java:187)
                                        	at com.facebook.react.ReactActivityDelegate.onActivityResult(ReactActivityDelegate.java:192)
                                        	at com.facebook.react.ReactActivity.onActivityResult(ReactActivity.java:79)
                                        	at android.app.Activity.onActivityResult(Activity.java:7571)
                                        	at android.app.Activity.internalDispatchActivityResult(Activity.java:9470)
                                        	at android.app.Activity.dispatchActivityResult(Activity.java:9447)
                                        	at android.app.ActivityThread.deliverResults(ActivityThread.java:6025)
                                        	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:5454)
                                        	at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:5500)
                                        	at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:73)
                                        	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:63)
                                        	at android.app.servertransaction.TransactionExecutor.executeLifecycleItem(TransactionExecutor.java:169)
                                        	at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:101)
                                        	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
                                        	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773)
                                        	at android.os.Handler.dispatchMessage(Handler.java:109)
                                        	at android.os.Looper.loopOnce(Looper.java:232)
                                        	at android.os.Looper.loop(Looper.java:317)
                                        	at android.app.ActivityThread.main(ActivityThread.java:8934)
                                        	at java.lang.reflect.Method.invoke(Native Method)
                                        	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
                                        	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

MANDATORY Reproducer

https://github.com/melissaosullivan/rn-activity-destroy-state-lost-repro/tree/main

Screenshots and Videos

No response

Activity

  1. devanshsaini11 commented on Jun 19, 2025

    @devanshsaini11
    Collaborator

    @melissaosullivan I was able to reproduce this locally based on steps you mentioned. Thanks for raising this.

  2. melissaosullivan commented on Jul 24, 2025

    @melissaosullivan
    Author

    @cortinico @cipolleschi Could one of you please take a look at this issue? I've created the repro app requested in #30277. Considering all the comments on that ticket, this longstanding bug impacts a wide range of developers and projects including the react-native-plaid-link-sdk.

  3. cortinico commented on Jul 24, 2025

    @cortinico
    Contributor

    When the app is killed and then restored, the activity result is processed before React Native is ready. The JavaScript callback is not executed, and you won't see "RESULT" or "Completed" logs, indicating the callback was lost.

    Yeah this looks like a bug. In theory the ReactActivity should be recreated correctly once you launch the app again. Not sure what's actually happening here.

    @cortinico @cipolleschi Could one of you please take a look at this issue?

    We're currently hyperfocused on New Architecture regressions at the moment, so I don't have an ETA on when we'll be able to look into this.

    Any community investigation and contribution would be more than welcome

  4. AshokKanchi commented on Dec 29, 2025

    @AshokKanchi

    Title
    Intermittent crash after tapping OK / check-mark after photo capture (device-specific)

    Description
    Hello 👋
    I’m facing an intermittent crash when using react-native-image-crop-picker.
    The issue does not happen every time and seems to be device-specific.

    In most cases, the camera opens and captures the photo correctly, but after tapping the OK / check-mark button, the app crashes on some devices.
    On other devices, the same flow works without any issues.

    Environment

    react-native: 0.81.0
    react: 19.1.0
    react-native-screens: 4.15.3
    react-native-image-crop-picker: 0.51.0

    Platform: Android 11
    Issue frequency: Random / device-specific

    Steps to Reproduce
    1.Open camera using react-native-image-crop-picker
    2.Capture a photo
    3.Tap OK / check-mark to confirm
    4.App crashes sometimes (not 100% reproducible)

    Expected Behavior
    1.The app should consistently return the captured image without crashing.

    Actual Behavior
    1.The app crashes intermittently after confirming the photo on some devices, while working fine on others.

    Additional Notes

    1.All permissions are granted
    2.Camera capture itself works
    3.Crash occurs only after confirming the image
    4.Works fine on some devices and fails on others

    Logs:

    12-29 19:51:21.510 3923 6704 E WindowManager: win=Window{1b22d93 u0 com.dev.tasklyhub/com.dev.tasklyhub.MainActivity} destroySurfaces: appStopped=true win.mWindowRemovalAllowed=false win.mRemoveOnExit=false win.mViewVisibility=8 caller=com.android.server.wm.ActivityRecord.destroySurfaces:5251 com.android.server.wm.ActivityRecord.destroySurfaces:5232 com.android.server.wm.ActivityRecord.notifyAppStopped:5291 com.android.server.wm.ActivityRecord.activityStopped:5918 com.android.server.wm.ActivityTaskManagerService.activityStopped:2595 android.app.IActivityTaskManager$Stub.onTransact:2223 android.os.Binder.execTransactInternal:1190
    12-29 19:51:31.077 15978 15978 E unknown:ReactHost: com.facebook.react.bridge.ReactNoCrashSoftException: raiseSoftException(onActivityResult(activity = "com.dev.tasklyhub.MainActivity@badc492", requestCode = "61111", resultCode = "-1", data = "null")): Tried to access onActivityResult while context is not ready
    12-29 19:51:31.276 3639 3668 E BufferQueueProducer: com.dev.tasklyhub/com.devrabbit.tasklyhub.MainActivity$_15978#0 disconnect: not connected (req=1)
    12-29 19:56:31.448 3639 5561 E BufferQueueProducer: com.dev.tasklyhub/com.dev.tasklyhub.MainActivity$_15978#0 disconnect: not connected (req=1)
    12-29 19:56:31.497 3923 4064 E WindowManager: win=Window{298f427 u0 com.dev.tasklyhub/com.dev.tasklyhub.MainActivity} destroySurfaces: appStopped=true win.mWindowRemovalAllowed=false win.mRemoveOnExit=false win.mViewVisibility=8 caller=com.android.server.wm.ActivityRecord.destroySurfaces:5251 com.android.server.wm.ActivityRecord.destroySurfaces:5232 com.android.server.wm.ActivityRecord.notifyAppStopped:5291 com.android.server.wm.ActivityRecord.activityStopped:5918 com.android.server.wm.ActivityTaskManagerService.activityStopped:2595 android.app.IActivityTaskManager$Stub.onTransact:2223 android.os.Binder.execTransactInternal:1190

  5. kumarAvinash108 commented on Jan 24, 2026

    @kumarAvinash108

    ped=true win.mWindowR

    did you found any solution?

  6. sam-shubham commented on Feb 4, 2026

    @sam-shubham

    hii @cortinico just wnet through the issue and looking forward to work on it. we can Queue activity results when React isn't ready, then process them once React initializes.

    can you correct me if i'm wrong or can i get assigned.

  7. dbobe commented on Sep 23, 2026

    @dbobe

    Still reproducible on React Native 0.86.3 (bridgeless / New Architecture) with Expo SDK 57 (expo 57.0.23, expo-image-picker 57.0.19, expo-modules-core 57.0.18), through a very common path: taking a photo with the camera.

    Repro

    1. Call ImagePicker.launchCameraAsync() from an Expo app.
    2. While the camera is open, kill the app's process: adb shell am kill <package>. Turning on "Don't keep activities" in Developer options gives the same result.
    3. Take the photo and confirm.

    Result: MainActivity is recreated, and logcat shows:

    ReactHost: Unhandled SoftException
    com.facebook.react.bridge.ReactNoCrashSoftException: raiseSoftException(onActivityResult(...)): Tried to access onActivityResult while context is not ready
    

    The result never reaches Expo's module registry, so ImagePicker.getPendingResultAsync(), the API Expo provides for exactly this recovery, returns null. We polled it for 9 s after the remount. The capture is lost.

    We saw this on a Galaxy Note 9 (Android 9) and on an API 36.1 emulator, both when only the activity was recreated and when the process was killed.

    This looks like exactly what #57051 fixes (holding activity results until the context is ready, then delivering them). We'd be glad to test it against this repro if that helps it move forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help Wanted :octocat:Issues ideal for external contributors.Issue: Author Provided ReproThis issue can be reproduced in Snack or an attached project.Platform: AndroidAndroid applications.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions