問題: アクティビティ B は常に false を返しますが、アクティビティ A 内で同じ KEY をチェックすると、結果は true になります。どうしてこれなの?キーを確認しましたが、両方のアクティビティでまったく同じです。
編集:ご協力いただきありがとうございます。ただし、提案を実装した後も、まだ運がありません。これが私が今持っているものです:
ActivityA, extends Activity Implements OnGesturePerformedListener
//How methods are called...
read(getApplicationContext(),"fav", posName);
write(getApplicationContext(), "fav", posName, false);
...
public Boolean read(Context context, String name, String key) {
SharedPreferences sP = context.getSharedPreferences(name, MODE_PRIVATE);
Boolean b = sP.getBoolean(key, false);
return b;
}
public void write(Context context, String name, String key, boolean value) {
SharedPreferences sP = context.getSharedPreferences(name, MODE_PRIVATE);
SharedPreferences.Editor editor = sP.edit();
editor.putBoolean(key, value);
editor.commit();
}
ActivityB, extends FragmentActivity
、サブクラス:
public static class SectionFragment extends Fragment
中身onActivityCreated()
SharedPreferences sP = getActivity().getSharedPreferences("fav", MODE_PRIVATE);
Boolean b = sP.getBoolean(posName, false);
結果 =b
常に等しいfalse
何か案は?