react-native: ReactContext: currentActivity is null when onActivityResult is called
I use addActivityEventListener
to listen for the result of an Intent.
- when I start the Intent RN calls
onHostPause
and releases the referencemCurrentActivity
inReactContext.java
. - my
onActivityResult
fires, but there is nocurrentActivity
set yet, becauseonHostResume
is called afterwards.
0.29 / Android / Mac
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 27 (11 by maintainers)
Commits related to this issue
- Add Activity to onActivityResult listener interface Summary: The Android lifecycle is weird: turns out `onActivityResult` is called before `onResume`. This means `getCurrentActivity()` could return t... — committed to facebook/react-native by foghina 8 years ago
- Add Activity to onActivityResult listener interface Summary: The Android lifecycle is weird: turns out `onActivityResult` is called before `onResume`. This means `getCurrentActivity()` could return t... — committed to HomePass/react-native by foghina 8 years ago
I hava the same issues. android version 0.36 when i used getCurrentActivity in ReactContextBaseJavaModule some times return null. I create ReactInstanceManager not in onCreate method,But in the onCreate after a period of time。 So there is no onHostResume method is called, passing the current activity to ReactContext. My solution is to create a ReactInstanceManager called after ReactInstanceManager.onHostResume.
@conover Did it fix your issues?
@fab1an, 0.32 becomes stable early next week and 0.33-rc is released. This issue has been there for a while so I don’t think we should rush and risk 0.32 stable and release it without a good 2 weeks of release-candidate testing. But thanks for caring and feel free to discuss more.
Ah yes, the problem there is the
ReactInstanceManager
gets destroyed when theActivity
is destroyed. I might fix that soon anyway as part of a different thing I’m working on.I can confirm this that I’ve run into this issue.
cc @foghina