I have an slider in that i have different buttons click events, When i am clicking button1 i am loading fragmentA in that am loading webservice, when clicking button 2 in slider i am loading fragmentB in that am loading webservice, And now When am pressing back button its moving to fragmentA but Again webservice is loading.I don't want to load webservice when going to back fragment.
The following is my base activity code in click event of buttons
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, fragment)
//.addToBackStack(backStateName)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.addToBackStack(null)
.commit();
In FragmentA i am retrieving date and time from webservice and i am saving those values in onsavedinstance state and i am setting those values in onActivityCreated if saved instance state in not null
public void onSaveInstanceState(Bundle outState) {
outState.putString("date", date);
outState.putString("time", time);
super.onSaveInstanceState(outState);
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if(savedInstanceState!=null){
tv_datevalue.setText(""+savedInstanceState.getString("date", ""));
tv_timevalue.setText(""+savedInstanceState.getString("time", ""));
}else{
loadWebService();
}
}
But every time it is loading webservice in onbackpressedinstead of showing previous values. The log statements in onSavedIntancestate are not displaying. i.e; onSavedIntancestate is never calling.