importjava.util.HashMap;importjava.util.Map;importandroid.content.Context;importandroid.content.SharedPreferences;publicclassSystemSharedpreferences{privateContextcontext;publicSystemSharedpreferences(Contextcontext){this.context=context;}//存数据publicbooleansaveMessage(Stringname,Stringage){booleanflage=false;SharedPreferencessharedpreferences=context.getSharedPreferences("IPConfig",Context.MODE_PRIVATE);SharedPreferences.Editoreditor=sharedpreferences.edit();editor.putString("name",name);editor.putString("age",age);flage=editor.commit();returnflage;}//取数据publicMap<String,String>getMessage(){Map<String,String>map=newHashMap<String,String>();SharedPreferencessharedPreferences=context.getSharedPreferences("IPConfig",Context.MODE_PRIVATE);Stringip=sharedPreferences.getString("name","");Stringport=sharedPreferences.getString("age","");map.put("name",name);map.put("age",age);returnmap;}}//调用//存入SystemSharedpreferencessystemSharedpreferences=newSystemSharedpreferences(getBaseContext());booleanflage=systemSharedpreferences.saveMessage(name,age);//取出SystemSharedpreferencessystemSharedpreferences=newSystemSharedpreferences(getBaseContext());Map<String,String>maps=systemSharedpreferences.getMessage();