• 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).
 
Back
Top Bottom