1

I have a ViewPager with 3 Fragment bind by FragmentPagerAdapter in a FragmentActivity,when I am switching to different app and after coming back to my app or after a incomming call the Fragments are not restoring to previous state,one fragments are completely disappeared and some of the fragments button click is not working..but in emulator its working fine

Kindly help me....

KousiK
  • 825
  • 7
  • 17
  • 39

1 Answers1

4

Override onActivityCreated in Fragment..

This method will be called when you come back to fragment

@Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
            // Do your stuff
}

And add this line to your parentActivity of all Fragments :

viewPager.setOffscreenPageLimit(3);

And switch to FragmentStatePagerAdapter insteasd of using FragmentPagerAdapter

SweetWisher ツ
  • 7,296
  • 2
  • 30
  • 74