android保存数据到SharedPreferences

来源:赵克立博客 分类: Android 标签:--发布时间:2018-04-19 14:21:29最后更新:2018-04-19 14:25:26浏览:1749
版权声明:
本文为博主原创文章,转载请声明原文链接...谢谢。o_0。
更新时间:
2018-04-19 14:25:26
温馨提示:
学无止境,技术类文章有它的时效性,请留意文章更新时间,如发现内容有误请留言指出,防止别人"踩坑",我会及时更新文章

保存值

//获取SharedPreferences对象
SharedPreferences sharedPre=mContext.getSharedPreferences("config", Context.MODE_PRIVATE);
//获取Editor对象
SharedPreferences.Editor editor=sharedPre.edit();
//设置参数
editor.putString("username","admin");
//提交
editor.apply();

获取值

 SharedPreferences sharedPre=  mContext.getSharedPreferences("config", Context.MODE_PRIVATE);
 sharePre.getString("username","");



微信号:kelicom QQ群:215861553 紧急求助须知
Win32/PHP/JS/Android/Python