Search code examples
androidsharedpreferencesandroid-sharedpreferences

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


Is time taken to get data from shared preferences on first time and then on second, third or fourth time for same key same or different?


Solution

  • About SharedPreferences.

    SharedPreferences caches after first load, so disk access to load data will take time but once. You can try to load SharedPreferences early in your test suite to avoid this penalty.

    For persisting your data you should opt for SharedPreferences.Editor.apply() instead of SharedPreferences.Editor.commit() since appy is asynchronous. But please do read the documentation about both to see which one applies in your case.

    SharedPreferences.Editor Documentation

    SharedPrerences Documention