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.