1# SharedPreferencesUsageDetector
2
3## Problem
4
5This linter detects the usage of `SharedPreferences` in Android code.
6`SharedPreferences` is discouraged for new development in favor of
7`ProtoDatastore`.
8
9## Explanation
10
11`ProtoDatastore` offers several advantages over `SharedPreferences`, including:
12
13*   Clear API contract defined (`getData()` and `updateData()`)
14*   Schema in form protocol buffer.
15*   Async APIs
16*   Durable
17*   Thread-safe and supports transactions.
18
19## Solution
20
21For new features, use `ProtoDatastore` instead of `SharedPreferences`. You can
22leverage `GuavaDatastore.java` which provides a convenient wrapper around
23`ProtoDatastore`.
24
25For existing code that uses `SharedPreferences`, you can suppress this lint
26warning.
27
28### Example
29
30The following code will trigger this lint warning:
31
32```java
33SharedPreferences prefs = getSharedPreferences("my_prefs", Context.MODE_PRIVATE);
34```
35