Skip to content

[Android] Shared ReactInstanceManager in a singleton between multiple activities failing while showing a modal #15108

Closed
@yurykorzun

Description

@yurykorzun

I integrated a React Native app into an existing Android app. When a native app requests a React Native view, I start a new activity with a React Native view in it. I wrapped ReactInstanceManager in a singleton class and initialize it when the Android app loads.

The problem I experience is that ReactInstanceManager cannot be shared between multiple instances of ReactNative views. For example, if I start one React Native activity and show a share sheet using the Share component, the next time I start a new activity and provide it the cached ReactInstanceManager, it will fail while trying to show a Modal. When the React Native tries to call mDialog.show it fails with android.view.WindowManager$BadTokenException: Unable to add window.
It looks like it tries to attach a dialog to a non-existent activity. It has something to do with the React Themed Context I guess.

It looks like ReactInstanceManager cannot be loaded once and shared safely between multiple instances of React Native views.

If anyone can share insight on how to share ReactInstanceManager properly, I would really appreciate that. Currently I am refreshing the manager every time I close a React Native Activity, but I would like to have a single instance.

  1. react-native -v: 0.42.3
  2. node -v: v6.11.0
  3. npm -v: 5.2.0
  4. platform: Android

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions