Programmatically restart the React Native app

Is it possible to programmatically restart the React Native application without writing my own code?

For example, I know from the answer to this question that I can restart the Android application using

Intent i = getBaseContext().getPackageManager() .getLaunchIntentForPackage( getBaseContext().getPackageName() ); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); 

Can I do the same with React Native?

+21
android ios react-native
source share
5 answers

If you want to restart only part of the JS, you can use the React Native Restart Package . This will work on both Android and iOS.

If you want to restart the entire application, there are currently no corresponding packages. If you want to create yourself, check out the following link

Creating an Android Custom Module for React Native

If you find it difficult to write JAVA base code, you can generate a template using the React Native Create Library

+22
source share

In addition to what was said above, you can restart the application using Codepush as follows:

 import CodePush from 'react-native-code-push'; CodePush.restartApp(); 

In fact, this is where the React Native Restart Package got its code from.

+11
source share

You can use ReactInstanceManager like this

  final ReactInstanceManager instanceManager = getReactInstanceManager(); instanceManager.recreateReactContextInBackground(); 
+3
source share

For iOS, React Native provides a "reboot" method via "DevSettings" https://github.com/facebook/react-native/blob/75f2da23c5d557862cf4b7bcdd8a1445b54d1c31/React/Modules/RCTDevSettings.mm#L240-L243

 import { NativeModules } from "react-native"; NativeModules.DevSettings.reload(); 
+3
source share

You can do the following:

 yarn add react-native-restart react-native link react-native-restart 

and use it as follows:

 import RNRestart from 'react-native-restart'; // Import package from node modules // Immediately reload the React Native Bundle RNRestart.Restart(); 
0
source share

All Articles