What to clear on logout

Data and storage Senior Kotlin 2.0+ API 24+ Reviewed By Best Latest Apps

Order the steps

Order the logout steps.

  • Navigate to login, clearing the back stack
  • Cancel WorkManager jobs for this user
  • Reset in-memory repositories and delete tokens
  • Clear the database, per-user DataStore and caches
  • Revoke the refresh token on the server and unregister push

Choose an answer, then open Show answer below to check it.

Show answer

Answer: B E D C A

  1. Cancel WorkManager jobs for this user So nothing writes or uploads during cleanup.
  2. Revoke the refresh token on the server and unregister push Stops the old session working anywhere.
  3. Clear the database, per-user DataStore and caches Removes private data.
  4. Reset in-memory repositories and delete tokens No stale state in singletons.
  5. Navigate to login, clearing the back stack The previous user's screens can't be reached with Back.

30-second answer

Everything tied to that user: tokens in secure storage, the Room database or the user's rows, DataStore preferences that are per-user, in-memory caches and repositories holding state, image and HTTP caches with private content, scheduled WorkManager jobs, notification channels or pending notifications, and push token registration on your server. Then reset navigation to the login screen.

Practise saying it · 40 s. No recording, just a timer

Explain what to clear on logout.

Say your answer out loud, then check which of these points you covered:

  • Tokens and server revocation
  • Database, DataStore, caches
  • WorkManager jobs
  • In-memory singletons
  • Reset navigation

Deep dive

Cancel unique work and periodic work before clearing data, so a job doesn't recreate it.

Singletons survive logout; give them a clear() or scope them to a user session component.

Clearing the database with clearAllTables() keeps the schema.

Tell the server to revoke the refresh token, not just delete it locally.

Common mistakes

  • Deleting the token but leaving cached data visible to the next user.
  • Forgetting WorkManager jobs that upload the old user's data later.
  • Leaving in-memory singletons with the previous user's state.

Senior take & follow-ups

A checklist answer is good here; order matters (cancel work first).

Follow-up questions

Think of your answer first, then open the hint.

  1. Why revoke on the server?

    Show hint

    A copied refresh token would otherwise keep working.

  2. How do you reset singletons?

    Show hint

    Clear them explicitly or rebuild a user-scoped component.

Compare on iOS: What to remove on logout The same checklist, with Keychain instead of Keystore-backed storage.

Suggest a fix if something here is wrong or out of date.