The essence of sharedpreferences is to store key-value key-value pairs of data based on XML files, typically to store some simple configuration information. Its storage location is under the/data/data/< package name >/shared_prefs directory.
Here only about Sharedpreferences basic additions and deletions to check the operation, simulation of a login to remember the password function.
Add a user node, save username Zhang San, password 666666
Getsharedpreferences ("User",0). Edit (). Putstring ("UserName","Zhang San"). Commit ();//Edit the value of username under the user node equals ' Zhang San 'Getsharedpreferences ("User",0). Edit (). Putstring ("Userpass","666666"). Commit ();//Edit the value of username under the user node equals ' 666666 '
See if the data you saved is correct
stringUserName = Getsharedpreferences ("User",0). GetString ("UserName","");//get the value of UserName: UserName = ' Zhang San 'stringUserpass = Getsharedpreferences ("User",0). GetString ("Userpass","");//get the value of Userpass: userpass= ' 666666 '
Specify to delete username and userpass data
Getsharedpreferences ("User"0). Edit (). Remove ("UserName"). Commit (); // to delete a node named username under the user node Getsharedpreferences ("User"0). Edit (). Remove ("userpass"). Commit (); // to delete a node named Userpass under the user node
Clear All data
Getsharedpreferences ("User"0). Edit (). Clear (). Commit ();
How to use Xamarin.android sharedpreferences