GetFragmentManager.findFragmentByTag() returns null
android, android-fragments, fragment
Solution
I was having the same problem of `findFragmentByTag()` always returning null.
Eventually I tracked it down, I was overriding `onSaveInstanceState()` in my Activity but not calling super. As soon as I fixed that `findFragmentByTag()` returned the Fragment as expected.
Problem
``` getFragmentManager().beginTransaction() .replace(R.id.graph_fragment_holder, new GraphFragment(), "GRAPH_FRAGMENT") .commit(); getFragmentManager().beginTransaction() .replace(R.id.list_fragment_holder, new ListFragment(), "LIST_FRAGMENT") .commit(); //getFragmentManager().executePendingTransactions(); GraphFragment graphFragment = (GraphFragment) getFragmentManager().findFragmentByTag("GRAPH_FRAGMENT"); graphFragment.setData(data); ListFragment listFragment = (ListFragment) getFragmentManager().findFragmentByTag("LIST_FRAGMENT"); listFragment.setData(data); ``` I've supplied a tag so I'm not sure why `findFragmentByTag()` returns `null`. What I've tried from reading other questions: `this.setRetainInstance(true)` in the `oncreate` of both `fragments`. Both `fragment` constructors are empty `public fragmentName(){}`. tried `executePendingTransactions` after adding the `fragments`. tried `add` instead of `replace` on the `fragments` (edited)