Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onSaveInstanceState not called on Fragment

Tags:

android

I am replacing a Fragment with another one:

    FragmentTransaction transaction = mFragmentManager.beginTransaction();

    transaction.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit);
    transaction.replace(R.id.main_container, nextFragment, nextFragment.getClass().toString());
    transaction.addToBackStack(nextFragment.getClass().toString());
    transaction.commit();

however, the fragment thats being replaced, its onSaveInstanceState is not called. what am i doing wrong?

like image 450
0xSina Avatar asked Mar 28 '14 20:03

0xSina


1 Answers

"In a Fragment, all of their lifecycle callbacks are directly tied to their parent Activity. So onSaveInstanceState gets called on the Fragment when its parent Activity has onSaveInstanceState called."

Look at this post:

FragmentActivity onSaveInstanceState not getting called

like image 127
kgmaize Avatar answered Nov 15 '22 15:11

kgmaize