[Android] state is not restored on activity recreation
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C++
- Star
- 127k
- Fork
- 25.3k
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 4
Mô tả
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
- generate a new react-native app
- remove
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|fontScale"inandroid/app/src/main/AndroidManifest.xml - render a long list of items in App.tsx
- run
yarn android - scroll to the bottom of the list an rotate device
- 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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với reproducer bắt buộc và android/app/src/main/AndroidManifest.xml cùng App.tsx của ứng dụng được tạo. Chạy yarn android, cuộn qua danh sách dài, xoay thiết bị và so sánh hành vi khi có và không có mục configChanges. Hoàn tất khi trạng thái của view liên quan, bao gồm cả vị trí cuộn, được giữ nguyên sau khi Android activity được tạo lại.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- android, react-native
- Lĩnh vực
- mobile-dev
- Loại issue
- Lỗi
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 30/100