Realm React-Native: Access same realm from JS(react native code) and android(java)

点点圈 提交于 2019-12-10 20:38:39

问题


I have a use case where i am receiving some data in android code(native). I want to insert this data into the same realm which is opened or made by my react code.

Or write in the same realm. How can I achieve this? All the help is appreciated. P.S. I know I can somehow make a native module and send data back to my JS and perform operations there.. but I am not sure it will happen if my app is not in foreground.

Right now I am running a service in background which will receive data and save it in realm.

Any way I can do this ??


回答1:


If I understood correctly, I just want to use Realm both on native and react native code correct?

If so, it should be as simple as initialising the Realms on both codes (with the same path), and write/query normally. I did this and it worked.




回答2:


I have the same requirement and tried accessing the same file from android and react-native which breaks my application. I changed to pathfile on one side to proof its pathfile related.

It would be great, if someone from the realm team can confirm this is/should work or not and what I should do to fix this issue. I assume more users will use services in android and need to access the data in react-native.

versions js: "realm": "^2.21.0", "react-native": "0.57.7",

version android: 'com.android.tools.build:gradle:3.2.1' minSdkVersion = 26



来源:https://stackoverflow.com/questions/43634172/realm-react-native-access-same-realm-from-jsreact-native-code-and-androidjav

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!