I am making a fitness app that allows users to make lists of fitness events. One of the options when making a new event is to select the location using a Google Map. This opens a new fragment, and causes all values on the current fragment to be reset. To prevent this from happening, I save any values that have been set by using onSaveInstanceState():
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mEventStr != null)
outState.putString("event", mEventStr);
if (mSelectStartDateTxtVw != null)
outState.putString("startDate", mSelectStartDateTxtVw.getText().toString());
if (mSelectStartTimeTxtVw != null)
outState.putString("startTime", mSelectStartTimeTxtVw.getText().toString());
if (mSelectEndDateTxtVw != null)
outState.putString("endDate", mSelectEndDateTxtVw.getText().toString());
if (mSelectEndTimeTxtVw != null)
outState.putString("endTime", mSelectEndTimeTxtVw.getText().toString());
if (mEventType != null)
outState.putString("eventType", mEventType);
if (mEventDescriptionEdTxt != null)
outState.putString("eventDescription", mEventDescriptionEdTxt.getText().toString());
}
Then, when the user has returned from the Google Map, I restore these values in onCreateView():
if (savedInstanceState != null) {
mEventStr = savedInstanceState.getString("event");
mSelectStartDateTxtVw.setText(savedInstanceState.getString("startDate"));
mSelectStartTimeTxtVw.setText(savedInstanceState.getString("startTime"));
mSelectEndDateTxtVw.setText(savedInstanceState.getString("endDate"));
mSelectEndTimeTxtVw.setText(savedInstanceState.getString("endTime"));
mEventType = savedInstanceState.getString("eventType");
mEventDescriptionEdTxt.setText(savedInstanceState.getString("eventDescription"));
}
This, however, does not seem to work. Does anyone have an idea of why this may be happening?