How to use Xamarin.android sharedpreferences

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.