How would you verify state restoration after Android screen rotation?
Instruction: Design and test restoration for a search/detail screen with a query, selection and editable draft. Distinguish ordinary rotation from background process recreation, and prevent duplicate actions or stale view updates.
Updated
Official answer
I would separate a rotation test from a process-recreation test. A normal rotation commonly recreates the Activity while retaining its scoped ViewModel; killing the process destroys that ViewModel. Handling only the first case leaves a real restoration gap.
For this screen, keep the query and selected record ID as small reconstruction inputs in saved state, and load record contents through the repository. Keep an important editable draft in durable storage according to the product's save policy. Standard views can restore supported view state when correctly identified; custom state needs its own save/restore contract. Do not put a large result list or bitmap into a saved-state Bundle.
On recreation, build the new UI and render current state once through the new lifecycle owner. Clear old view bindings and listeners. Avoid launching an irreversible operation from every onCreate call or showing a one-time navigation event again merely because the observer reattached.
Test rotation with a query, selection, scroll position, draft and an in-flight request. Then separately test supported process recreation while backgrounded, restoring IDs and loading data without retaining the old view. Test missing/deleted data and failed reloads. A force-stop or explicit finish has different saved-state semantics and should not be described as the same scenario.
I would not lock orientation or declare configuration handling just to hide a restoration bug. The screen must also adapt to its new available space.