从 Sharedpreferences 中获取数据所花费的时间,在第一次调用和以后的调用中,相同还是不同?

Time taken to get data from Sharedpreferences, in fist call and later calls, same or different?

第一次从共享首选项中获取数据所花费的时间是相同的还是不同的?

关于 SharedPreferences。

SharedPreferences 在第一次加载后缓存,因此磁盘访问加载数据将花费时间但一次。您可以尝试在测试套件中尽早加载 SharedPreferences 以避免这种损失。

为了持久化您的数据,您应该选择 SharedPreferences.Editor.apply() 而不是 SharedPreferences.Editor.commit(),因为 appy 是异步的。但是请务必阅读关于两者的文档,看看哪一个适用于您的情况。

SharedPreferences.Editor Documentation

SharedPrerences Documention