react / react/react-native

[Android] state is not restored on activity recreation

未关闭
#54,575 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Issue: Author Provided Repro Needs: React Native Team Attention Platform: Android
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从必需的 reproducer 以及生成应用的 android/app/src/main/AndroidManifest.xml 和 App.tsx 开始。运行 yarn android,滚动浏览长列表,旋转设备,并比较有无 configChanges 条目时的行为。在 Android activity 重新创建后,相关 view 状态(包括滚动位置)仍得到保留,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
android, react-native
领域
mobile-dev
Issue 类型
缺陷
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。