0

I'm using the following method to delete a key element on the SharedPreferences of my app. I'm calling it from within a fragment. The problem is that the element is never deleted from SharedPreferences and I get no LogCat output. Is there something wrong with this method? Context perhaps? The deleteFromSharedPreferences is located in a class called Utils and the triggering method is located on a fragment called PagerFragment. Any feedback would be greatly appreciated.

public class PagerFragment extends Fragment {
        private void deleteCity() {
            deleteFromSharedPref(mCityId, getContext());
        }
}

public class Utils {
        public static void deleteFromSharedPref(String key, Context context) {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.remove(key);
        editor.apply();
    }
}
CBA110
  • 1,072
  • 2
  • 18
  • 37

0 Answers0