react / react/react-native

[Android] state is not restored on activity recreation

オープン
#54,575 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Issue: Author Provided Repro Needs: React Native Team Attention Platform: Android
主要言語
C++
スター
127k
フォーク
25.3k
平均マージ
1日 23時間
マージ済み PR(30日)
4

説明

Description

On Android, when the Activity is recreated, either by memory pressure or a configuration change the entire view state is lost / recreated by react native.

For this reason, most templates restrict activity recreation on android.
According to our android team, google might not support these changes in future android versions (The future is adaptive: Changes to orientation and resizability APIs in Android 16).

We raised a similar issue in react-native-screens, where an analysis showed that the root cause is that react-native itself does not support activity recreation.

According to us, this is a bug and react native should properly support activity recreation on android.

Steps to reproduce
  1. generate a new react-native app
  2. remove android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|fontScale" in android/app/src/main/AndroidManifest.xml
  3. render a long list of items in App.tsx
  4. run yarn android
  5. scroll to the bottom of the list an rotate device
  6. scroll position is lost
React Native Version

0.82.1

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info
System:
  OS: macOS 15.7.2
  CPU: (11) arm64 Apple M3 Pro
  Memory: 151.86 MB / 36.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 25.2.1
    path: /Users/d0261170/.local/share/mise/installs/node/25.2.1/bin/node
  Yarn:
    version: 1.22.22
    path: /opt/homebrew/bin/yarn
  npm:
    version: 11.6.2
    path: /Users/d0261170/.local/share/mise/installs/node/25.2.1/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2025.2 AI-252.25557.131.2521.14432022
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 21.0.9
    path: /Users/d0261170/.local/share/mise/installs/java/zulu-21.46.19.0/bin/javac
  Ruby:
    version: 3.4.7
    path: /Users/d0261170/.local/share/mise/installs/ruby/3.4.7/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.0
    wanted: 20.0.0
  react:
    installed: 19.1.1
    wanted: 19.1.1
  react-native:
    installed: 0.82.1
    wanted: 0.82.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false
Stacktrace or Logs
not applicable
MANDATORY Reproducer

https://github.com/jakobfelsatdm/rn-activity-reproducer

Screenshots and Videos

No response

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

必須のreproducerと、生成されたアプリの android/app/src/main/AndroidManifest.xml および App.tsx から始めます。yarn android を実行し、長いリストをスクロールし、デバイスを回転させ、configChanges エントリがある場合とない場合の挙動を比較します。Android アクティビティの再作成後も、スクロール位置を含む対象ビューの状態が保持されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
android, react-native
領域
mobile-dev
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。