zoukankan      html  css  js  c++  java
  • Android -- SharedPreferences存储信息

    背景                                                                                            

    SharedPreferences我觉得是最容易上手的,以xml方式存储。

    代码                                                                                            

    public class share {
        public static void saveInfo(Context context,String username,String password)
        {
            SharedPreferences sp = context.getSharedPreferences("config", context.MODE_PRIVATE);
            Editor editor = sp.edit();
            editor.putString("username", username);
            editor.putString("password", password);
            editor.commit();
        }
    }

    主要就是开启edit,然后写数据,然后commit。

    SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE);
            String username = sp.getString("username", "");
            String password = sp.getString("password", "");
            usernameText.setText(username);
            passwordText.setText(password);

    上面的是读数据。

    我是天王盖地虎的分割线                                                                 

    源代码:http://pan.baidu.com/s/1dD1Qx01

    savefile_share.zip

    转载请注明出处:http://www.cnblogs.com/yydcdut/p/3720656.html

  • 相关阅读:
    weblogic内存快速配置
    weblogic优化参数
    weblogic10.3.6忘记用户名或者密码的解决方法
    Linux shell 环境变量及有效范围
    linux文本处理常用命令
    Scala实践7
    Scala实践5
    Scala实践4
    Scala实践3
    Scala实践2
  • 原文地址:https://www.cnblogs.com/yydcdut/p/3720656.html
Copyright © 2011-2022 走看看