React Native Android: Showing an Activity from Java

社会主义新天地 提交于 2019-12-04 04:05:57

Hope I understand your issue correctly: What you want is to show an Activity (java code) from javascript code.

I would suggest to implement a native module: https://facebook.github.io/react-native/docs/native-modules-android.html

Native module is a bridge between java and javascript. So if your native 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 that helps. You also can transfer data between them as well, please check at the document.

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