Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically Restart a React Native App

Is it possible to programmatically restart a React Native app without writing any native code?

For instance, I know from the answer to this question that I can restart an Android app with:

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

Can I do the same with React Native?

like image 663
Adam Jakiela Avatar asked May 27 '16 18:05

Adam Jakiela


People also ask

How do I restart a react-native app?

Drag the file Restart. xcodeproj from /node_modules/react-native-restart/ios into the Libraries group in the Project navigator. Ensure that Copy items if needed is UNCHECKED!

How do I refresh react-native code?

Pull to Refresh functionality is implemented using RefreshControl component in React Native. RefreshControl is used inside a ScrollView or ListView to add pull to refresh functionality. When the ScrollView is at scrollY: 0 , swiping down triggers an onRefresh event.

How do I reload react-native app on emulator?

For Android emulator press "CTRL + M" with keyboard on emulator for reloading the react native project.


1 Answers

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

If you want to restart the whole application, There are no react native packages as of now. If you want to create on your own, then check the following link

Building the custom Android module for React Native

If you find difficulty in writing the base JAVA code, You can generate the boilerplate using React Native Create Library

UPDATE:

From 0.62, React Native have added DevSettings.reload(). So, if you want to reload programmatically while developing you can use that. Note that this method does not work in production!

Click here for Doc

like image 130
Sriraman Avatar answered Sep 20 '22 19:09

Sriraman