-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Android ReactActivity Destroy Prevents Successful OnActivityResult Calls #30277
Comments
Are there any updates on this issue? This is a problem with low memory devices as well when the main application launches other activities (like launching camera) and then the Android OS kills the activity that launched the camera along with the ReactContext. |
@zsweigart Did you find any workaround for this issue? Maybe provide an own ReactInstanceManager implementation? |
We have not worked on finding a work around and are currently accepting the rate errors until this is fixed |
For the sake of cross-referencing most related issues from other modules and working on a workaround, I've created a repo: https://github.com/HugoGresse/react-native-issue-30277/blob/main/README.md |
Workaround for |
What changed to cause this? Is it a ReactNative change or an Android SDK update? |
I can't believe there is no update on this issue. |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions. |
This issue needs attention, it impact a lot of apps through many libraries. |
Same problem (image-crop-picker). |
Facing the same issue... I think this issue needs attention. |
This issue needs attention, facing the same thing! |
Any one with a solution? |
Currently facing the same issue with react-native-app-auth |
As a workaround, I can imagine one would use a Handler on the main thread (which is guaranteed here anyway), poll whether reactContext is still null and give up after a few retries (trying to cover as many crashes as possible but not waiting too long). |
Facing the same issue... I think this issue needs attention. |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue needs attention! |
any solutions? |
Ca we have someones attention to this ? @react-native-bot @cipolleschi @cortinico |
can someone create a clear reproducer using this template? The original issue is pretty old and the latest reproducer is from a year ago. |
I'm unsure it will help as I find it was dependent of the device, using the dev settings to not keep the activities does not seems to have the same effect. I can send you a Xiaomi Redmi 7A if needed |
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 theReactActivity
theReactActivity
has to start up.The React Native startup flow is:
ReactActivity#onCreate
ReactActivityDelegate#onCreate
ReactActivityDelegate#loadApp
ReactDelegate#loadApp
ReactRootView#startReactApplication
ReactInstanceManager#createReactContextInBackground
ReactInstanceManager#recreateReactContextInBackgroundInner
ReactInstanceManager#recreateReactContextInBackgroundFromBundleLoader
ReactInstanceManager#recreateReactContextInBackground
ReactInstanceManager#runCreateReactContextOnNewThread
At this point
ReactInstanceManager#setupReactContext
is called on a background thread.Meanwhile,
ReactActivity#onActivityResult
is called. In the Android activity lifecycleonActivityResult
is called even beforeonResume
(for reference. The calls fromReactActivity#onActivityResult
pass through a few layers and end up atReactInstanceManager#onActivityResult
which checks if theReactContext
is nullBecause the context is being built on a background thread there is no guarantee that
currentContext
will be initialized at this point. FurthermoreReactInstanceManager#createReactContext
is a fairly intensive function so it is actually very likely thatcurrentContext
is null.This means that
ReactContext#onActivityResult
is not called and therefore, the data cannot be passed back to theActivityEventListener
which in my sample is theReactContextBaseJavaModule
.React Native version:
Steps To Reproduce
react-native run-android
Do Not Keep Activities
toOn
Background Process Limit
toNo background processes
Open Activity
Go to Web
-> This should kill the original process in the background due to your developer settings; however, on some emulators I have noticed it does not. One way to guarantee this is to runadb shell am kill com.react_native_crash
which will simulate a system process kill. Note you cannot kill the process by swiping it away because the OS will lose the information about the backstack.adb shell am start -n com.react_native_crash/.RedirectActivity -d "redirect://crash"
Return Result
Expected Results
After these steps in the console you should see
which would indicate the
onActivityResult
was called properly and the callback to the js code was executed.Snack, code example, screenshot, or link to a repository:
https://github.com/zsweigart/react-native-crash
The text was updated successfully, but these errors were encountered: