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
commit()
is synchronously, apply()
is asynchronous
apply()
is void function.
commit()
returns true if the new values were successfully written to persistent storage.
apply()
guarantees complete before switching states , you don't need to worry about Android component lifecycles
If you dont use value returned from commit()
and you're using commit()
from main thread, use apply()
instead of commit()