0

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.

Prasanthi
  • 19
  • 7
  • Please provide a solution , i have searched most of links but none gave proper solution to me. – Prasanthi Jul 28 '14 at 07:22
  • Have you checked ThanhHHs and Vašek's answers here? http://stackoverflow.com/questions/15313598/once-for-all-how-to-correctly-save-instance-state-of-fragments-in-back-stack – 0101100101 Jul 28 '14 at 07:32
  • Hi Vlad, i gone through that link i didn't find any solution.One more thing log statements in OnSavedInstanceState also not printing. – Prasanthi Jul 28 '14 at 07:56
  • Please anyone provide answer to my question it's urgent to me. – Prasanthi Jul 28 '14 at 10:45

0 Answers0