0Pricing
Android Academy · Lesson

rememberSaveable

Keep state across configuration changes.

rememberSaveable is a free Android Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Android Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Problem with remember

remember survives recomposition, but not configuration changes like screen rotation. When the activity is recreated, remembered state is lost and resets to its initial value.

Enter rememberSaveable

rememberSaveable works like remember but also saves the value across configuration changes and process death, then restores it.

var count by rememberSaveable { mutableStateOf(0) }

Rotation Example

With plain remember, rotating the phone resets a counter to 0. With rememberSaveable, the count is preserved through the rotation.

How It Saves

Behind the scenes rememberSaveable stores the value in the activity's saved instance state Bundle, the same mechanism the old View system used for onSaveInstanceState.

Supported Types

It automatically saves types that fit in a Bundle: primitives, String, and Parcelable objects. Custom types need a little extra work.

Process Death

If Android kills your app in the background to reclaim memory, then the user returns, rememberSaveable restores the saved state so the screen looks as the user left it.

Custom Savers

For a type that is not automatically saveable, provide a Saver that converts it to and from a saveable form. Compose offers helpers like listSaver and mapSaver.

val saver = listSaver<MyState, Any>(
    save = { listOf(it.a, it.b) },
    restore = { MyState(it[0] as Int, it[1] as String) }
)

Using a Custom Saver

Pass the saver to rememberSaveable via its saver parameter so Compose knows how to persist your type.

var state by rememberSaveable(stateSaver = saver) {
    mutableStateOf(MyState(0, ""))
}

When to Use Which

Use rememberSaveable for state the user would be annoyed to lose on rotation — form input, scroll position, selected tab. Use plain remember for transient UI state that is fine to reset.

Not for Big Data

The saved Bundle is small. Do not store large data (bitmaps, long lists) in rememberSaveable. Keep heavy data in a ViewModel or repository and save only small identifiers.

Putting It Together

A form field that survives rotation thanks to rememberSaveable.

@Composable
fun LoginField() {
    var email by rememberSaveable { mutableStateOf("") }
    TextField(
        value = email,
        onValueChange = { email = it }
    )
}

Quick Check

What does rememberSaveable do that remember does not?

Recap

rememberSaveable:

  • Survives rotation and process death, not just recomposition.
  • Auto-saves primitives, String, and Parcelable.
  • Use a Saver for custom types.
  • Keep saved data small; big data belongs in a ViewModel.

Frequently asked questions

Is the “rememberSaveable” lesson free?

Yes — the full text of “rememberSaveable” is free to read here on the web, and the Android Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Android Academy course, upgrade to CoddyKit PRO.

What will I learn in “rememberSaveable”?

Keep state across configuration changes. You practise Android Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Android Academy?

No prior experience is required. Android Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “rememberSaveable” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Android Academy lesson?

Yes. Every Android Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. State with remember and mutableStateOf
  2. Recomposition Explained
  3. State Hoisting
  4. rememberSaveable
← Back to Android Academy