避免在react native + android 12的方向改变时重启



问题-

当我改变设备方向时,我的react-native应用程序突然重新启动。这是两个月前的工作

在我将android版本升级到v12, Build #SP1A.210812.016后,我开始遇到这个问题。

这是我的代码- AndroidManifest.xml

<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
android:requestLegacyExternalStorage="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this);
super.onCreate(savedInstanceState);
}
...
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Intent intent = new Intent("onConfigurationChanged");
intent.putExtra("newConfig", newConfig);
this.sendBroadcast(intent);
}

如果你知道是什么原因造成的,请帮助?

提前感谢!

使用:"react-native"0.64.1"

我能够解决它。对于那些遇到同样问题的人,尝试将screenLayout添加到AndroidManifest.xml中。代码应该是这样的:

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"

这就解决了问题。

最新更新