避免重新启动React Native&#x2B的方向更改; Android 12

发布于 2025-01-30 01:18:19 字数 1619 浏览 6 评论 0原文

问题 -

每当我更改设备方向时,我的反应本地应用都会突然重新启动。 这是两个月前的工作。

将Android版本升级到V12后,我开始遇到问题,构建#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);
      }

如果您知道是什么原因引起的,请帮助您吗?

提前致谢!

使用:“反应本”:“ 0.64.1”

Problem -

My react-native app suddenly keeps restarting whenever I change the device orientation.
This was working 2 months back.

I started experiencing the problem after I upgraded my android version to v12, Build #SP1A.210812.016.

Here are my codes - 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);
      }

Please help if you have any idea what's causing this?

Thanks in advance!

using : "react-native": "0.64.1"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白云不回头 2025-02-06 01:18:19

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

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

解决了问题。

I was able to solve it. For those who have encountered the same problem, try adding screenLayout to AndroidManifest.xml. Code should look like this.

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

That solved the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文