Your app is killed for memory; what runs when the user returns?

Tests process death versus config change. Answer: no callback on kill; return runs onCreate with savedInstanceState, onStart, and onResume. ViewModels die in process death; use SavedStateHandle. Red flag: claiming onDestroy fires or ViewModels survive it.
What's really being asked
Whether you understand the difference between the system reclaiming a process and a configuration change, and whether you architect state restoration defensively rather than relying on memory.
The full answer
First, the OS terminates the process silently when under memory pressure; no Activity or Fragment lifecycle callback is guaranteed beforehand, so onDestroy does not run. When the user later returns, the system creates a new process, calls Application.onCreate, then reconstructs the Activity with onCreate passing a non-null savedInstanceState Bundle, followed by onStart and onResume. Second, contrast this with a configuration change like rotation: there the process stays alive, the Activity is destroyed and recreated, but ViewModel instances survive in memory. After process death, ViewModels are gone entirely unless you use the Saved State module for ViewModel. Third, design guidance: persist lightweight UI state such as scroll position or form input via SavedStateHandle or onSaveInstanceState, keep business data and large objects in repositories backed by persistent storage or disk cache, never store bitmaps or large lists in a Bundle to avoid TransactionTooLargeException, and test process death explicitly with adb shell am kill or by enabling background process limits rather than only using Do Not Keep Activities.
The mistakes people make
Saying onStop or onDestroy is called before the OS kills the process. Asserting that ViewModels automatically survive process death without SavedState. Treating process death and configuration changes as identical scenarios. Storing heavy objects in savedInstanceState. Relying on static singletons to hold user progress across process recreation.
What usually comes next
How does SavedStateHandle interact with ViewModel scoping? What are the exact Bundle size limits and what happens when you exceed them? How do you handle this in Jetpack Compose with rememberSaveable versus ViewModel? What happens to a foreground service or WorkManager task when its hosting process is killed? How would you restore navigation stack state after process death?
A concrete example
A ride-sharing app displays a route map with user-selected pickup and drop-off pins. If the process dies, the app should not cache the decoded route bitmap or large place objects in savedInstanceState. Instead it stores only the two place IDs and camera position in SavedStateHandle. On recreation, the Activity reads those IDs, fetches route data from the repository or network, and re-renders the map.
Interview question
When architecting state restoration for an Activity that may be killed under memory pressure, which approach follows Android best practices?
- a.Store decoded bitmaps and large lists in savedInstanceState for instant UI restoration and rely on ViewModels to survive automatically.
- b.Use onDestroy to persist critical business data to disk because it is guaranteed to run before the OS kills the process.
- c.Treat process death identically to a configuration change by assuming ViewModels remain in memory and savedInstanceState is null.
- d.Persist lightweight UI state like scroll position via SavedStateHandle and keep heavy data in repositories backed by persistent storage or disk cache.Correct
Why? this is the answer
Lightweight UI state belongs in SavedStateHandle while heavy data must live in repositories or disk cache to avoid TransactionTooLargeException, and ViewModel instances do not survive process death automatically. The most tempting distractor assumes onDestroy is guaranteed to run, but the OS can silently kill the process without invoking any Activity lifecycle callback.
Just read this? Test yourself on what you have been reading.
Read the original → developer.android.com
- #android
- #activity-lifecycle
- #process-death
- #viewmodel
- #state-restoration
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on android — each one lists the topics its interview covers.
See open roles