Using your exact code inside an abstract class, I cannot reproduce this problem. I created an abstract class, ReplaceFragment .
My Main class extends FragmentActivity and sets the content view for the fragment.
Inside the Fragment class, I set up a ListView . When the list item is clicked, I do the following:
getListView().setItemChecked(index, true); // Check what fragment is currently shown, replace if needed. DetailsFragment details = (DetailsFragment) getFragmentManager().findFragmentById(R.id.details); if (details == null || details.getShownIndex() != index) { details = DetailsFragment.newInstance(index); ReplaceFragment.replaceFragment(...); }
My output in LogCat every time I clicked:
10-07 12: 19: 07.688: V / FragmentManager (861): remove: DetailsFragment {40527d48 # 1 id = 0x7f040003} nesting = 2
10-07 12: 19: 07.688: V / FragmentManager (861): movefrom RESUMED: DetailsFragment {40527d48 # 1 id = 0x7f040003}
10-07 12: 19: 07.688: E / DetailsFragment (861): Details onPause ()
10-07 12: 19: 07.688: V / FragmentManager (861): movefrom STARTED: DetailsFragment {40527d48 # 1 id = 0x7f040003}
10-07 12: 19: 07.688: E / DetailsFragment (861): Details onStop ()
10-07 12: 19: 07.699: V / FragmentManager (861): movefrom STOPPED: DetailsFragment {40527d48 # 1 id = 0x7f040003}
Submit additional information about your implementation to help you further.
Mike P.
source share