What's the difference between commit() and apply() in SharedPreferences

后端 未结 8 2301
你的背包
你的背包 2020-11-22 10:03

I am using SharedPreferences in my android app. I am using both commit() and apply() method from shared preference. When I use AVD 2.3

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 10:15

    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.

    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.

    http://developer.android.com/reference/android/content/SharedPreferences.Editor.html#apply()

提交回复
热议问题