SharedPreferences
Persist simple key-value data across app sessions using SharedPreferences. Learn to save, read, and remove preferences.
Persistent Storage Options
Android offers several ways to store data locally:
- SharedPreferences — simple key-value pairs (settings, tokens)
- Room — structured SQLite database (complex data)
- DataStore — modern async replacement for SharedPreferences
- Files — raw file I/O
SharedPreferences is perfect for simple settings and user preferences.
What Is SharedPreferences?
SharedPreferences stores data as key-value pairs in an XML file on the device. It supports:
- String
- Int / Long / Float
- Boolean
- Set<String>
Data persists across app restarts and survives configuration changes (rotation).