android采用SharedPreferences保存用户偏好设置参数
android中SharedPreferences最常被用来保存用户的一些个人配置。
1、main.xml
public class ShareService {private Context context;private SharedPreferences preferences = null;public ShareService(Context context) {this.context = context;}public void save(String name, String pwd) {preferences = context.getSharedPreferences("temp", Context.MODE_PRIVATE);Editor editor = preferences.edit();editor.putString("name", name);editor.putString("password", pwd);editor.commit();}public Map<String, String> read(){Map<String, String> map = new HashMap<String, String>();preferences = context.getSharedPreferences("temp", Context.MODE_PRIVATE);map.put("name", preferences.getString("name", "isEnmpty"));map.put("password", preferences.getString("password", "isEnmpty"));return map;}}