-
Notifications
You must be signed in to change notification settings - Fork 24k
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
Is sharing ReactInstanceManager across multiple activities broken? #6410
Comments
Removing the calls to I have moved the call to This occurs because onResume sets the current activity, but onDestroy is called after this (when going back) which then removes the reference. |
@AndrewJack My activities extend ReactActivity, as intended, in this case you can't really prevent the call to Seems like this issue was introduced when Add a base activity for React Native apps was merged. |
Just make your own ReactActivity |
hmm... I feel like that misses the whole point of having a base activity for react native apps. |
@AndrewJack I wasn't aware of this, but according to the docs
Also |
@guyca You can just override the |
@satya164 Thanks for the response. I might be experiencing a brain fart, but how does overriding |
@guyca Yeah, missed that. |
@guyca Interesting about onResume sets the current activity, in ReactInstanceManagerImpl & ReactContext This wouldn't cause a leak as long as every new activity calls onResume, which will set a new current activity. However, if an activity started that didn't call onResume, and the previous activity was destroyed then that activity would leak. Note: |
@satya164 are there any planes to address this issue? Should I make a pull request? |
@guyca Sure. Ping me when you do. |
@satya164 wonderful, will do. |
@satya164 here's my take on fixing this issue. What do you think? |
I agree.
This seems like a scenario not many people run into (so far). Until it becomes common I don't think we need to support it in the base class. |
@facebook-github-bot answered |
Closing this issue as @mkonicek says the question asked has been answered. Please help us by asking questions on StackOverflow. StackOverflow is amazing for Q&A: it has a reputation system, voting, the ability to mark a question as answered. Because of the reputation system it is likely the community will see and answer your question there. This also helps us use the GitHub bug tracker for bugs only. |
We have the same issue |
1 similar comment
We have the same issue |
ReactInstanceManager singleton across multiple activities |
Still an issue and no clear solution to it. |
I'm trying to share a ReactInstanceManager singleton across multiple activities. I've wired my ReactInstanceManager instance the my activities life cycle methods, so when
ReactActivity.onDestroy
is called, themReactInstanceManager
also gets destroyed and thenmCurrentReactContext
is set to null.When opening a new activity and instanciating react views with the singelton manager everything works fine. But when I close the second activity with the back button, it's
onDestroy()
is invoked afteronResume()
of the first activity. Now when I try to interact with react views i get the following warning message:03-10 13:35:33.164 1627-1627/com.awesomeproject W/unknown:React: Unable to handle touch in JS as the catalyst instance has not been attached
since
mReactInstanceManager.getCurrentReactContext()
inhandleTouchEvent()
returns null.Is sharing ReactInstanceManager across activities/fragment still supported?
I'm running RN 0.20.0 on Android.
The repro scenario is very simple:
create a react activity (MainActivity). Open another activity from it, and click the back button to go back to the MainActivity.
results: any RN view in MainActivity can't be interacted with.
Logs:
The text was updated successfully, but these errors were encountered: