Use SharePreferences to access data (MOOC notes), sharepreferences

Source: Internet
Author: User

Use SharePreferences to access data (MOOC notes), sharepreferences

0. video address: http://www.imooc.com/video/3265

1. Use SharePreferences to access data:

Public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); SharedPreferences pref = PreferenceManager. getdefasharsharedpreferences (MainActivity. this); // Method 2: SharedPreferences // pref = getSharedPreferences ("mypref", MODE_PRIVATE); Editor editor = pref. edit (); editor. putString ("name", ""); editor. putBoolean ("default", true); editor. putInt ("age", 30); editor. putLong ("time", System. currentTimeMillis (); editor. commit (); // submit // System. out. println (pref. getInt ("age", 0 ));}}
View Code

2. How to set the value?

3. How to view data files? 1) run the program, and then open DDMS> File Explorer> data> package name> shared_prefs> pref. xml> Export 2) open the File:

 

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.