什么是)的共享preference commit()和应用(之差 [英] What's the difference between commit() and apply() in Shared Preference

查看:106
本文介绍了什么是)的共享preference commit()和应用(之差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的共享preference在我的Andr​​oid应用程序。我同时使用提交()申请从共享preference()方法。当我使用AVD 2.3就说明没有错误,但是当我在AVD 2.1运行code,适用()方法显示错误。 那么,什么是这两者之间的区别是什么?而仅使用提交()我可以存储在preference值没有任何问题?

I am using shared preference in my android app. I am using both commit() and apply() method from shared preference. When I use AVD 2.3 it shows no error, but when I run the code in AVD 2.1, apply() method shows error. SO what's the difference between these two? And by using only commit() can I store the preference value without any problem?

推荐答案

适用()中添加了2.3,它承诺的返回布尔值,指示成功或失败。

apply() was added in 2.3, it commits without returning a boolean indicating success or failure.

提交()返回真正如果保存作品,,否则。

commit() returns true if the save works, false otherwise.

适用()加入作为Android开发团队发现,几乎没有人注意到返回值的通知,因此适用于速度更快,因为它是异步的。

apply() was added as the Android dev team noticed that almost no one took notice of the return value, so apply is faster as it is asynchronous.

<一个href="http://developer.android.com/reference/android/content/Shared$p$pferences.Editor.html#apply()">http://developer.android.com/reference/android/content/Shared$p$pferences.Editor.html#apply()

这篇关于什么是)的共享preference commit()和应用(之差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆