Data storage is an important feature in Android development. The following describes how to store key-value pairs using XML files. SharedPreferences can be used in four steps: 1) Get SharedPreferences object 2) Get SharedPrefercences. editor object 3) Use putXXX to save the data 4) Save the data in the file the following example uses SharedPreferences to store simple data and the stored content is test. xml. The content of the file is as follows: [html] www.2cto.com <? Xml version = '1. 0' encoding = 'utf-8' standalone = 'Yes'?> <Map> <string name = "name"> zhanghu </string> <string name = "habit"> android, surfing, playing basketball </string> </map> is implemented below: The specific implementation code is as follows: [java] public class SharedPreferences_Activity extends Activity {private EditText editText1, editText2, editText3, editText4; private Button button1, button2; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_shared_preferences _); editText1 = (EditText) findViewById (R. id. editname); editText2 = (EditText) findViewById (R. id. edithabbit); editText3 = (EditText) findViewById (R. id. editname2); editText4 = (EditText) findViewById (R. id. edithabbit2); button1 = (Button) findViewById (R. id. commit); button2 = (Button) findViewById (R. id. display); button1.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {// TODO Auto-generated method stub // get the SharedPreferences object (step 1) sharedPreferences mySharedPreferences = getSharedPreferences ("test", Activity. MODE_PRIVATE); // obtain SharedPrefercences. editor object (step 2) SharedPreferences. editor editor = mySharedPreferences. edit (); // use putXXX to save the data (Step 3) editor. putString ("name", editText1.getText (). toString (); editor. putString ("habit", editText2.getText (). toString (); // Save the data in the file (step 4) editor. commit (); editText1.setText (""); editText2.setText ("") ;}}); button2.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {// TODO Auto-generated method stub SharedPreferences sharedPreferences = getSharedPreferences ("test", Activity. MODE_PRIVATE); String nameString = sharedPreferences. getString ("name", ""); String habitString = sharedPreferences. getString ("habit", ""); editText3.setText (nameString); editText4.setText (habitString) ;}}@ Override public boolean onCreateOptionsMenu (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. activity_shared_preferences _, menu); return true ;}}