首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android采取SharedPreferences保存用户偏好设置参数

2012-11-25 
android采用SharedPreferences保存用户偏好设置参数android中SharedPreferences最常被用来保存用户的一些

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;}}


热点排行