SharedPreferences临时存储数据 如记住密码
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();
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。