• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Beware of SharedPreferences commit...

This is a good tip and one aspect of SharedPreferences that I usually forget. I want to add one little note... this "apply" is only API 9 (Android 2.3 - Gingerbread) and up.

Good practice would be to just check for which SDK the user is like so (in the most basic form):

[HIGH=JAVA]
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
editor.apply();
} else {
editor.commit();
}
[/HIGH]

If you use apply only it will crash if ran on a lower SDK (phone less than gingerbread).
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones