In my project I use fragment named PassengerInformation.java. In that fragment I use onSaveInstanceState and onCreate method.In onCreate method I supposed to clear sharedPreferences if there is no bundle passed from onSaveInstanceState, if onSaveInstanceState pass a bundle I would not need to clear sharedPreferences. My question is when I press back, onSaveInstanceState is not called I supposed to log it but log does not print anything.
Thanks
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//clear sharedpreferences PassengerInformation is firsttime loaded
if( savedInstanceState == null ) {
Log.i("clear PassengerInformation", "sharedPreferences clear");
edit.clear().commit();
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
outState.putBoolean("clearPreferences", false);
Log.i("saveInstanceState PassengerInformation", "save");
}