Home > Article > Web Front-end > Detailed explanation of Android native development with React-native
This article mainly introduces the detailed explanation of React-native bridging Android native development. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.
In the long journey of developing RN, sooner or later one will have to come into contact with the native development of Android. The author will introduce the ups and downs. For a novice who does not understand Android, it is just starting It’s a bit difficult, but everything is difficult at the beginning. The language is clear, and the principles are the same.
During the development process, the navigation function of Amap must be integrated. If you haven't found a good wheel, just write native code, and then use JS to call the native navigation module.
First register the module
The meaning is to combine the classes with Only after registering in RN can you use JS to call
##
public class AnExampleReactPackage implements ReactPackage { @Override public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { return Collections.emptyList(); } @Override public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { List<NativeModule> modules = new ArrayList<>(); modules.add(new NaviActivity(reactContext)); return modules; } }where modules.add(new NaviActivity(reactContext)); means adding an Android native activity module
This module can define a solution, and RN can call it directly (@ReactMethod must be declared on the method)
##
@ReactMethod public void showFengMap(String mapID){ Activity currentActivity = getCurrentActivity(); Intent intent = new Intent(currentActivity, 页面名.class); currentActivity.startActivity(intent); }
in the MainApplication of the Android app,
@Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), new AnExampleReactPackage() ); }
import { NativeModules } from 'react-native'; export default NativeModules.NaviActivity;
CommonAndroidUntils.show();
For a novice to directly integrate the Amap map in android studio, it is a bit difficult at first. But after understanding it, I feel better. Let’s briefly explain the problems encountered and remind myself , Help others
The .jar voice package dragged directly cannot be importedThe solution is to right-click the .jar package, click on the option to import .jar, and wait for synchronization That’s it.
The rest are minor problems that can be easily solved based on the demo and documentation.
Related recommendations:
The above is the detailed content of Detailed explanation of Android native development with React-native. For more information, please follow other related articles on the PHP Chinese website!