Android -- SharedPreferences存储信息

时间:2014-05-18 00:35:54   收藏:0   阅读:360

背景                                                                                            

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

代码                                                                                            

bubuko.com,布布扣
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();
    }
}
bubuko.com,布布扣

主要就是开启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

Android -- SharedPreferences存储信息,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!