shivcena
shivcena

Reputation: 2053

where my datas store if i use sharedpreference in android

i learned about Sharedpreferences in android to save user name and password thats works well, please refer my code below,

SavePreferences("MEM1", "two");
SavePreferences("MEM2", "one");
SavePreferences("MEM3", "three");
SavePreferences("MEM3", "four");
LoadPreferences();
private void SavePreferences(String key, String value){
    SharedPreferences sharedPreferences = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString(key, value);
    editor.commit();
   }

   private void LoadPreferences(){
    SharedPreferences sharedPreferences = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE);
    String strSavedMem1 = sharedPreferences.getString("MEM1", "");
    String strSavedMem2 = sharedPreferences.getString("MEM2", "");       
   } 

my doubt is where my given datas are stored if i use Sharedpreferences.Actually what happens if i use Sharedpreferences.

Upvotes: 0

Views: 150

Answers (1)

Vivek Khandelwal
Vivek Khandelwal

Reputation: 7849

The shared preference will be stored in internal memory of the devices inside the package folder which will be located at /data/data/your.package.name/shared_prefs.

You can try yourself and see the list of all the preferences stored there using ls command in shell or file explorer in adt.

All those are stored in a xml format.

For your example there will be a shared preference stored at /data/data/your.package.name/shared_prefs/MY_SHARED_PREF.xml.

TIP When storing password you should always encrypt the password before storing. Read this article

Upvotes: 1

Related Questions