i have a problem. I want to restore last fragment opened before close my application and i would like to use SharedPreferences so i put into the onCreateView of each fragment a snippet of code that save a string to shared preferences and in the Main Activity i've this
if(savedIstanceState == null) {
pref = new SharedPref(this);
String prefe = pref.getPreString("LastPage");
if(prefe == "0") {
fragment = new Fragment0();
} else if(prefe == "1") {
fragment = new Fragment1();
} else if(prefe == "2") {
fragment = new Fragment2();
} else {
fragment = new Fragment3();
}
getFragmentManager().beginTransaction().add(R.id.container, fragment).commit();
}
But return always Fragment3 also if in the preferences there are for example 0. Why?