清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
Android提供了SharePreference方便程序存储自己的key-value数据,使用非常方便,不用自己再却写文件了。通过SharePreference保存的文件为一个标准的xml文件。
public void saveToSharedPreference(View v){
sp = this.getSharedPreferences("config.txt", Context.MODE_PRIVATE);
//得到sharedpreference的编辑器
SharedPreferences.Editor editor = sp.edit();
editor.putString("title","www.sharejs.com");
editor.putBoolean("success",true);
//提交数据
editor.commit();
Toast.makeText(this,"保存到sharedpreference成功",Toast.LENGTH_SHORT).show();
//读取SharePreference的内容
String tel = sp.getString("title","没有获取到值");
Toast.makeText(this,tel,Toast.LENGTH_SHORT).show();
}