以编程方式重启React Native App [英] Programmatically Restart a React Native App
问题描述
是否可以在不编写任何本机代码的情况下以编程方式重启React Native应用程序?
Is it possible to programmatically restart a React Native app without writing any native code?
例如,我从此问题的答案中知道我可以使用以下方式重新启动Android应用程序:
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);
我可以对React Native进行同样的操作吗?
Can I do the same with React Native?
推荐答案
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.
如果您想重新启动整个应用程序,那么到目前为止,还没有任何React Native软件包.如果您想自己创建,请检查以下链接
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
如果您难以编写基本的JAVA代码,则可以使用 React生成样板本机创建库
If you find difficulty in writing the base JAVA code, You can generate the boilerplate using React Native Create Library
更新:
从0.62开始,React Native添加了DevSettings.reload()
.因此,如果要以编程方式重新加载,则从现在开始不需要任何第三方软件包.
From 0.62, React Native have added DevSettings.reload()
. So, if you want to reload programmatically, you don't need any third part packages from now on.
这篇关于以编程方式重启React Native App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!