how to use shared preference object ?

Report
Question
807 views

Shared Preference Object use to save details in application as local database in form of key value pair.

Please explain why do you think this question should be reported?

Report Cancel
== 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

Leave an comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>