SharedPreferences are used to store primitive data types in Android such as int, long, float, string. SharedPreferences have an added advantage over storing data in singleton class as Singleton class can store data and available throughout the app but if you exit the application all the data will lost. But in SharedPreferences if you exit out of your application or even if you switch off your Android device even then the data persists.
How to store data in SharedPreferences
Suppose to store the user id in SharedPreferences create a class SharedPrefernceManager and define the below methods in it. "setUserId" method will be used to store data and "getUserId" will be used to get data.