Android Development: Sharedpreferences store data, get data
Email:[email protected]
Development Environment : Win7 64-bit,Android Studio.
About Sharedpreferences. Personal understanding of it is understood as a lightweight database. The Access form is the same as map: <key,value>, stored as an XML file.
I just use it to store the login information and login status so that I can read the information locally every time I log in.
A. Storage
/** * Save personal information locally * /sharedpreferences sharedpreferences = getsharedpreferences ("Intveh", Context.mode_ PRIVATE); Sharedpreferences.editor editor = Sharedpreferences.edit ();//Get editor //should also record user_id editor.putstring (" UserID ", userid); Editor.putstring ("Phone", userphone); Editor.putstring ("password", userpassword); Log Login Status editor.putstring ("status", "1"); Editor.commit ();//Submit Changes
Two. Read
Sharedpreferences sharedpreferences = getsharedpreferences ("Intveh", activity.mode_private); String userId = sharedpreferences.getstring ("userid", ""); String status = sharedpreferences.getstring ("status", "0");
Please note: sharedpreferences.getstring ("Key", "default value returned when key does not exist").
Many other about sharedpreferences, can participate: http://www.cnblogs.com/linjiqin/archive/2011/05/26/2059133.html
Android Development: Sharedpreferences store data, get data