• 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

  • 相关阅读:
    30 tcp编码, udp编码 pycharm输出带颜色, tcp实现的聊天室
    29 网络相关知识 socket
    c++ 程序
    solr 5.4安装
    Linux之ss
    filezilla 证书使用
    mongodb安装,使用
    wireshark抓包发现1506字节包
    python之模块的显要属性
    正则表达式之去除空行
  • 原文地址:https://www.cnblogs.com/yydcdut/p/3720656.html
Copyright © 2020-2023  润新知