Is this correct?
SharedPreferences are stored in database开发者_Go百科s?
No it is not correct. SharedPreferences
are stored as XML files in your applications directory.
I am agreed with @Octavian answer (up voted), it is stored inside the file.
SharedPreferrences are stored in databases?
As i have written answer, NO, its stores inside the file inside your project directory.
To view this file, go to DDMS Perspective, click on the File Explorer.
From File Explorer, data -> data -> your project -> shared_prefs
.
Above, shared_prefs is the folder contains all the shared preferences you have declared and used.
Actually shared preferences store value into a variable .it is saved as like key-value pair
below is the code is used for store and retrieve values through shared preference values.
SharedPreferences prefs=getSharedPreferences("Key", 0);
Editor e= prefs.edit();
e.putString("Name", "AAA");
e.commit();
For retrieve the shared prefs value use below code
SharedPreferences prefs=getSharedPreferences("Key", 0);
String s= prefs.getString("Name", "");
精彩评论