I am including react native to my existing android application. I have one activity(say A) that is starting activity B. A activity sends some data in Bundle(consider some Custom Objects POJO) that B needs to render its view. Now I want my Activity B to contain React Native View. How will the objects(POJO) come from Activity A be sent to React Native code**(JavaScipt Code)**?
I know some time has passed, but maybe someone is still looking for an answer.
If you want to send object from JavaScript to ReactNative (let's say as an method argument), which is unfortunately not mentioned in documentation:
let map = {
name: 'message1',
surname: 'message2',
}
NativeModules.BluetoothModule.sendObject(map);
And get it in android:
@ReactMethod
public void sendObject(ReadableMap readableMap){
Log.i(TAG, readableMap.toString());
//you can decode it here like:
String name = readableMap.getString("name");
//or just parse it as json
}
Now for the other way (from Java to Javascript) you can use either Callbacs, Promises or Events. This part is described in documentation here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With