当前位置:网站首页>你已经用 SharedPrefrence 的 apply() 替换 commit() 了吗?
你已经用 SharedPrefrence 的 apply() 替换 commit() 了吗?
2022-04-21 18:08:00 【InfoQ】
commit()commit()
commit() 和 apply() 到底有什么异同?
- 二者都是提交 Prefrence 修改数据;
- 二者都是原子过程。
commit()- Commit your preferences changes back from this Editor to the
- {@link SharedPreferences} object it is editing. This atomically
- performs the requested modifications, replacing whatever is currently
- in the SharedPreferences.
- <p>Note that when two editors are modifying preferences at the same
- time, the last one to call commit wins.
- <p>If you don't care about the return value and you're
- using《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》开源this from your application's main thread, consider
- using {@link #apply} instead.
- @return Returns true if the new values were successfully written
- to persistent storage.*/boolean commit();
commit()- 会返回执行结果。
- 如果不考虑结果并且是在主线程执行可以考虑
apply()。
apply()- Commit your preferences changes back from this Editor to the
- {@link SharedPreferences} object it is editing. This atomically
- performs the requested modifications, replacing whatever is currently
- in the SharedPreferences.
- <p>Note that when two editors are modifying preferences at the same
- time, the last one to call apply wins.
- <p>Unlike {@link #commit}, which writes its preferences out
- to persistent storage synchronously, {@link #apply}
- commits its changes to the in-memory
- {@link SharedPreferences} immediately but starts an
- asynchronous commit to disk and you won't be notified of
- any failures. If another editor on this
最后:学习总结——Android框架体系架构知识脑图(纯手绘xmind文档)

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://xie.infoq.cn/article/a1e665a707a240d018f2d423b
边栏推荐
- 为什么基础设施工程师更喜欢MySQL?
- What can MCU do? Do you have any interesting works made by MCU or open source hardware
- MATLAB中的图形绘制
- LogStash~LogStash的input(input)
- LogStash~LogStash一站式教程(持续更新中)
- Logstash ~ how logstash works
- Is qiniu financial management useful? Is it safe?
- 爬虫案例01
- LogStash~LogStash的output(输出)
- Headline we media operation secret script. If you stick to it, you can beat 90% of the people
猜你喜欢

Easy to use example

Huawei URPF

Download times remaining, link + email can be left

The conflict between Russia and Ukraine raised concerns. The five eye network security department suggested that allies strengthen the protection of key infrastructure

After reading this tutorial, you will have your own satellite (DIY full explanation)

修改van-dropdown-menu默认高度

【acwing】166. 数独****(DFS)

单片机diy作品鉴赏,初学者进来膜拜

【论文精读】Stable Linear Structures and Seam Measurements for Parallax Image Stitching

移动平台WorkPlus集成化办公,打造企业全场景业务生态
随机推荐
mysql汉化-workbench汉化-xml文件
Integer面试解析、equals与==的区别
看完这篇教程,你将拥有自己的一个卫星(diy全程详解)
LogStash~LogStash的output(输出)
LogStash~LogStash的filter(过滤)
[intensive reading of Thesis] stable linear structures and seam measurements for parallelax image stitching
Build a short video platform and copy a demo of the login interface
Laxcus distributed operation redundancy and fault tolerance node
人员不足、供应链断裂,危机之下制造业该如何自救?
Is qiniu financial management useful? Is it safe?
使用K3S创建本地开发集群
吃了这个开源小玩意让单片机开发和Arduino一样高效
VS2019 visual studio 终端调试乱码问题
用户发送请求到执行controller方法的过程发生了什么
小小的模糊查询,竟来来回回修改了3次代码?找个电子厂上班吧
laravel-soar(2.x) - 自动监控输出 SQL 优化建议、辅助 laravel 应用 SQL 优化
Logstash ~ how logstash works
干货|app自动化测试之Appium 源码分析
你必须懂也可以懂的微服务系列三:服务调用
LogStash~LogStash的input(input)