存储文件:
(1)创建SharedPreferenced sp=Context.getSharedPreferenced(“data”,MODE_PRIVATE)对象
(2)通过sp.edit()方法创建SharedPreferdences.Editor editor对象
(3)调用put函数传入相应的键值对
(4)调用commit方法进行提交。
SharedPreferences sp=context.getSharedPreferences("data",Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sp.edit();
editor.putString("account",account);
editor.putString("password",password);
editor.commit();
return true;
读取文件:
(1) SharedPreferenced sp=get SharedPreferenced(data",MODE_PRIVATE)
(2)String data=sp.getString(“name”,"")//在读取的时候保证键相同以及数据类型相同
删除文件数据:
editor.remove(“key”)//删除键值对
editor.clear()//删除所有数据
editor.commit()方法提交
本文地址:https://blog.csdn.net/qq_42627388/article/details/107142211
如对本文有疑问, 点击进行留言回复!!
Error running app: Default Activity Not Found
如何用HMS Nearby Service给自己的App添加近距离数据传输功能
BlockChain:2020年7月10日世界人工智能大会WAIC《链智未来 赋能产业区块链主题论坛》(四)
网友评论