javascript - React Native Android: Showing an Activity from Java - Stack Overflow

I need to show an Activity ( Native android, Java ) in React-native.I know it have been asked few time

I need to show an Activity ( Native android, Java ) in React-native. I know it have been asked few times, But none helped me. I didn't find any tutorial or documentations on how to call/open the activity in React-Native. where to put the activity and how to register/add it to project.

Is there any tutorial or sample code?

I'm using react-native-camera , when i run it from RN, it shows a view from rn-camera, i looked into it's source code but it doesn't have an Activity.

If you could tell which modules for react-native are using activities it could help as well. (showing an android activity in react native).

There is some documentations on how to add react native to existing android projects but i couldn't find any guide on how to import an activity from android.

I'd really appreciate your help.

I need to show an Activity ( Native android, Java ) in React-native. I know it have been asked few times, But none helped me. I didn't find any tutorial or documentations on how to call/open the activity in React-Native. where to put the activity and how to register/add it to project.

Is there any tutorial or sample code?

I'm using react-native-camera , when i run it from RN, it shows a view from rn-camera, i looked into it's source code but it doesn't have an Activity.

If you could tell which modules for react-native are using activities it could help as well. (showing an android activity in react native).

There is some documentations on how to add react native to existing android projects but i couldn't find any guide on how to import an activity from android.

I'd really appreciate your help.

Share Improve this question asked Jan 17, 2017 at 13:16 Ata MohammadiAta Mohammadi 3,5506 gold badges43 silver badges71 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745250274a4618637.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信