How to use shared preferences to store and retrieve
data:
To store data:
SharedPreferences initialPref =
getSharedPreferences("pref",MODE_PRIVATE);
Editor
et=initialPref.edit();
String s1 = “data tostore”;
et.putString("DATA",s1);
et.commit();
To retrieve data stored in
sharedpreferences:
SharedPreferences
initialPref =getSharedPreferences("pref",MODE_PRIVATE);
String retrieveddata=initialPref.getString("DATA","");
Toast.makeText(getApplicationContext(),retrieveddata , Toast.LENGTH_LONG).show();
No comments:
Post a Comment