标签:
1 public void save(String name, String age){ 2 SharedPreferences preference = mcontext.getSharedPreferences("app_preference", Context.MODE_PRIVATE); 3 Editor editor = preference.edit(); 4 editor.putString("name", name); 5 editor.putString("age", age); 6 editor.commit(); 7 } 8 9 public Map<String, String> getPreference(){ 10 Map<String, String> param = new HashMap<String, String>(); 11 SharedPreferences preference = mcontext.getSharedPreferences("app_preference", Context.MODE_PRIVATE); 12 param.put("name", preference.getString("name", "")); 13 param.put("age", preference.getString("age", "")); 14 15 return param; 16 }
1 service = new PreferenceService(MainActivity.this); 2 Map<String, String> param = service.getPreference(); 3 4 name = (EditText)this.findViewById(R.id.name); 5 name.setText(param.get("name")); 6 age = (EditText)this.findViewById(R.id.age); 7 age.setText(param.get("age"));
熟悉AndroidAPI系列14——SharedPreferences和保存用户设置
标签:
原文地址:http://www.cnblogs.com/lya-nju/p/4211922.html