SharedPreferences 的使用

来源:互联网 发布:算法基础怎么样 编辑:程序博客网 时间:2024/06/10 09:36
1.保存
//将用户ID保存起来
SharedPreferences share = getSharedPreferences("fzgj", Context.MODE_PRIVATE);
SharedPreferences.Editor editor =share .edit();//获取编辑器
editor.putString("Myid", textilesbutlerusersid);
editor.commit();//提交修改(现在建议用editor.apply();

2.获取
SharedPreferences share=getSharedPreferences("fzgj", Activity.MODE_WORLD_READABLE);
myid= share.getString("Myid","0");

0 0