React Native - How Can I Emit An Event To Rn From Mainactivity.java?
In the React Native AppState library: iOS has three states background->inactive->active Android only has background->active When an Android app is fully backgrounded the M
Solution 1:
Try updating your MainActivity.java like this:
publicclassMainActivityextendsReactActivity {
@Override
publicvoidonStop() {
super.onStop();
WritableMap params = Arguments.createMap(); // add here the data you want to sendparams.putString("event", "ActivityonStop"); // <- example
getReactInstanceManager().getCurrentReactContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("onStop", params);
}
}
Let me know if this works. In my apps I usually send the events from a class that extends ReactContextBaseJavaModule
where I can access the context just by calling getReactApplicationContext()
, but it seems that it might work if you can obtain the ReactContext
from the ReactInstanceManager
.
Post a Comment for "React Native - How Can I Emit An Event To Rn From Mainactivity.java?"