Nie mogę zapisać danych do SharePreference

0

Witam,
Mam taki problem nie mogę zapisać danych do SharePrefeerence. Dane zapisuje w adapterze. Jak debuguje kod w tym miejscu pojawia się null.

public class MySharepreference {

    public static final String PREFS_NAME = "POSITION";
    public static final String POSITION = "current";
    public String nameString;

    public MySharepreference() {
        super();
    }


    public void saveNumberCard(Context context, String position) {
        SharedPreferences settings;
        SharedPreferences.Editor editor;
        settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
        editor = settings.edit();
        editor.putString(POSITION, position);
        editor.commit();
    }

    public String getNumberCard(Context context) {
        SharedPreferences sharedPreferences;
        sharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
        if (sharedPreferences.contains(POSITION)) {
            nameString = sharedPreferences.getString(POSITION, "");
        }
        return nameString;
    }

}

onBindViewHolder

 @Override
    public void onBindViewHolder(CardViewHolder holder, final int position) {

  mySharepreference = new MySharepreference();

        if (position == lastCheckedPos) {
            mySharepreference.saveNumberCard(mContext, card.getNumberCard());
}
0

Co dokładnie się dzieje? Gdzie wyskakuje ten null? Zmienna settings jest null? Spróbuj zamiast mContext przekazać getActivity().

1 użytkowników online, w tym zalogowanych: 0, gości: 1