onSaveInstanceState() là callback để lưu trạng thái UI tạm thời (như vị trí scroll) trước khi activity bị destroy do configuration change.
- Bundle này được truyền vào
onCreate()hoặconRestoreInstanceState(). - Khác với lưu trữ lâu dài như SharedPreferences hay database.
- Dùng nó cho trạng thái tạm thời dễ lưu hơn là phải tạo lại UI từ đầu.
onSaveInstanceState() is a callback that saves transient UI state (like scroll position) before the activity is destroyed due to configuration changes.
- The Bundle is passed to
onCreate()oronRestoreInstanceState(). - This is different from permanent storage like SharedPreferences or database.
- Use it for temporary state that's cheap to save but better than recreating UI from scratch.