For me the problem was that I was passing Activity to the constructor, not Context
public Adapter(Activity activity, List<MediaItem> items, boolean can) {
mItems = items;
canEdit = can;
mActivity = activity;
}
and using this activity to getDefaultSharedPreferences(), so I changed the Activity to Context and I was still calling the Adapter constructor with MainActivity.this