So in my MainActivity i am using SharedPreferences when checking boolean values doing like this.
public boolean uptadevalues(boolean updatedvalue) {
SharedPreferences preferences = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (mPremiumVQuery) {
Log.d(TAG, "Called uptadevalues mPremiumVQuery");
editor.putBoolean(mPremiumVString, true);
editor.apply();
} else {
editor.putBoolean(mPremiumVString, false);
editor.apply();
}
Log.d(TAG, "Called uptadevalues ");
return updatedvalue;
}
I know that mPremiumQuery is true because Log.d(TAG, "Called uptadevalues mPremiumVQuery");
appears on the logcat. So that means that the SharedPreference should be Writing
the preference.
On fragment:
public boolean getPremiumValues() {
Log.d(TAG, "getPremiumValues");
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
return sp.getBoolean(mPremiumVString, false);
}
and then on button click
case R.id.button5:
if (getPremiumValues()) {
** open activity **
} else {
** dialog ** }
It is always showing the dialog but it realy should be opening the new activity. I can't see where is my error! Thanks for any help.
UPDATE:
The problem was that I was using different methods to access SharedPreferences as @piotr.wittchen said.
Has many said to change from commit(); to apply(); i tried and no diference its made and has it is recomended to use apply(); by google I stayed with it.