ViewPager with three tabs. In the middle of a little man (WaveProgressBar). This little man is filled with liquid, when I press a button, but when I switch to another tab, and then come back to the little man, he is reset and filled with liquid in a new way, how to make it not dumped?

tried to use view_pager.setOffscreenPageLimit() gave nothing.

Another interesting point, in horizontal orientation, it is not reset.

enter image description here

    1 answer 1

    Override the onSaveInstanceState() method:

     @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); getSupportFragmentManager().putFragment(outState,"fragmentInstanceSaved",getSupportFragmentManager().findFragmentById(R.id.fragment_container)); } 

    And add the following to the onCreate method:

     if(savedInstanceState!=null){ Fragment fragment = getSupportFragmentManager().getFragment(savedInstanceState,"fragmentInstanceSaved"); //recreate your preserved fragment here }else{ //goto ur default activity or fragment.... }