I want to pass data from android native activity to react native js file. I can pass data from react-native to android. But i want to pass when i click button in activity. PLease help me to resolve this issue.
Asked
Active
Viewed 729 times
1 Answers
1
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.YourModule.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

M. Wojcik
- 2,301
- 3
- 23
- 31