Design and Implementation of the registration interface (3) implement data temporary storage and sharedptr with SharedPerferences

Source: Internet
Author: User

Design and Implementation of the registration interface (3) implement data temporary storage and sharedptr with SharedPerferences

Development steps:

  • Create a SharedPerferences interface object and use its putString method to put the relevant public data
  • Write the verified registered account to this file
  • Submit data
  • Customer prompt
1 // Register_Activity.java 2 3 if (flag) {4 SharedPreferences. editor editor = getSharedPreferences ("publicData", MODE_PRIVATE ). edit (); // create a SharedPerferences interface object 5 editor. putString ("account", txtRegAccount. getText (). toString (). trim (); // use the putString method of the SharedPerferences interface object to put the relevant public data 6 editor. commit (); // submit the data 7 Toast. makeText (getApplicationContext (), "New User Registration successful! ", Toast. LENGTH_LONG ). show (); // displays the customer's prompt: 8 9 Intent intent = getIntent (); 10 intent. setClass (Register_Activity.this, LoginActivity. class); 11 startActivity (intent); 12}

When logging in, you must obtain the public account data in SharedPerferences. The Code is as follows:

1 //loginActivity.java   2       SharedPreferences preferences = getSharedPreferences("publicData",MODE_WORLD_READABLE);3         String account= preferences.getString("account","");4         this.txtAccount.setText(account);

Run:

Verify the data file:

(1) Find the data storage file publicData set by SharedPerferences through DDMS

(2) Export publicData. xml using the File Explorer export Function

(3) Open publicdata. xml in notepad to verify its content.

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.