Where did my State go
summary
Activities, fragments and views keep getting recreated for reasons beyond rotation: toggling Dark Theme triggers a UI mode configuration change that recreates started activities, multi‑window forces different lifecycle states so onPause/onResume is unreliable for media, and background process death destroys memory (no workaround). ViewModel survives recreation but not process death so use SavedStateHandle (via SavedStateViewModelFactory) for persistence; custom views must implement BaseSavedState and set IDs. Test these with AndroidX testing using launchFragmentInContainer and Scenario.recreate or moveToState; opt out of multiwindow with resizableActivity=false or declare configChanges=uiMode as a last resort.
AI-written summary · about
chapters (5)
related talks
45mFalsehoods Android Developers Believe About Lifecycles
34mThe Life and Death of an Android Activity
30mSurviving a discontinuous world
36mManaging Data Restoration with the Architecture Components
38mActivities in the Wild: Exploring the Activity Lifecycle
39mFrustration-free orientation changes
41mViewModels, LiveData and Lifecycles, oh my!
23mMaster of Lifecycle
