Life · 3 / 4

The counter that will not count

State in Compose

Easycomposestate

Repair the counter so that every click updates its label and the value survives ordinary Activity recreation on rotation.

Assume Android Compose with the Activity's standard SavedStateRegistry, a small Int value and no integer overflow. Durable storage or reopening an explicitly finished screen is outside the contract.

Check: clicks produce 0 → 1 → 2; an ordinary recomposition keeps 2; rotation restores 2; a new independent opening after finishing starts at 0. Saving UI state.

Your code
Solution