Persist Login State

This lesson will cover how to store login state in the Android key-value storage.

Flow overview #

When LoginActivity is opened, we need to check the login state:

  • If the user is logged in already, we close LoginActivity and open MainActivity straightaway.
  • If the user is not logged in, we proceed to the regular flow and save the login state in the end.

Shared preferences #

In Android, to store a simple key-value data SharedPreferences can be used. This storage support saving the following types of data:

  • String
  • boolean
  • int
  • long
  • float
  • Set<String> values
...