how to use shared preference object ?
ReportQuestion
3 years ago 807 views
Shared Preference Object use to save details in application as local database in form of key value pair.
== Save Data in Shared Preference =======
SharedPreferences preferences = context.getSharedPreferences("ANYNAME", Context.MODE_PRIVATE);
SharedPreferences.Editor prefeditor = preferences.edit();
prefeditor.putString("ANY_KEY", "VALUE");
prefeditor.apply();
=== retrive value from SF========
SharedPreferences preferences = context.getSharedPreferences("ANYNAME", Context.MODE_PRIVATE);
String data = preferences.getString("ANY_KEY", "default value");
Thread Reply