Android 永久保存简单数据

转载: http://blog.csdn.net/xzlawin/article/details/45959033


方法1:

存数据:

SharedPreferences userInfo = this.getSharedPreferences("user_info", 0);
userInfo.edit().putString("name", nameet.getText().toString()).commit();
userInfo.edit().putString("password", passwordet.getText().toString()).commit();

读数据

SharedPreferences userInfo = this.getSharedPreferences("user_info", 0);
nameet.setText(userInfo.getString("name", ""));
passwordet.setText(userInfo.getString("password", ""));


方法2:

存数据:

SharedPreferences setting = getSharedPreferences("setting", 0);
                SharedPreferences.Editor editor = setting.edit();
                editor.putString("apiUrl", "hello").commit();

读数据

SharedPreferences setting =  getSharedPreferences("setting", 0);
        String apiUrl=setting.getString("apiUrl","");



posted @ 2018-02-08 16:03  正怒月神  阅读(750)  评论(0编辑  收藏  举报