React Native Android: display activity with Java

I need to show an action (native android, Java) in React-native. I know that they asked him several times, but no one helped me. I have not found any tutorial or documentation on how to call / open activity in React-Native. where to set the task and how to register / add it to the project.

Is there a tutorial or sample code?

I use the reaction-native camera, when I launch it from RN, it shows the view from the rn-camera, I looked at the source code in it, but it does not have Activity.

If you could specify which modules for react-native use actions, this can also help. (showing the activity of the android in the native reaction).

There are some documents on how to add a reaction to native existing Android projects, but I could not find a single guide on how to import activity from Android.

I am very grateful for your help.

+5
source share
1 answer

I hope I understand your problem correctly: You want to show an action (java code) from javascript code.

I would suggest implementing your own module: https://facebook.imtqy.com/react-native/docs/native-modules-android.html

A native module is a bridge between java and javascript. Therefore, if your own module has this:

@Override public String getName() { return "YourModule"; } @ReactMethod public void showYourActivity() { Intent intent = new Intent(mContext, YourActivity.class); // mContext got from your overriden constructor getCurrentActivity().startActivity(intent); } 

then in your js code:

 import {NativeModules} from 'react-native'; NativeModule.YourModule.showYourActivity(); 

hope this helps. You can also transfer data between them, please check the document.

+1
source

Source: https://habr.com/ru/post/1262931/


All Articles