SharedPreferences - Android

Viewed 170

I have a little doubt about the SharedPreferences in Android.

To delete a preference, we mainly have two options:

First:

SharedPreferences.Editor edit = (Editor) getSharedPreferences(Constants.APP_DEFAULT_PREF, MODE_PRIVATE).edit();
edit.putString(Constants.PREF_ACC, null);
edit.commit();

Second:

SharedPreferences.Editor edit = (Editor) getSharedPreferences(Constants.APP_DEFAULT_PREF, MODE_PRIVATE).edit();
edit.remove(Constants.PREF_ACC);
edit.commit();

In either case, fetching Constants.PREF_ACC value from SharedPreferences will return null.

I was wondering which one should I prefer. Is there any memory related issues in either of them? What will the System.gc behavior be with them?

3 Answers
Related