Please help me solve my problem.
I have a MainActivity with a frame. I want to replace some fragments with framelayout. Now I am facing problems, these are:
1) I created and placed fragment A in framelayout. Fragment A is called onCreateView ... etc.
2) Then I created and placed the fragment B in the layout ... Fragment A was placed in the backstack, and it was called onPause() (not called onDeattach() , onDestroy ...)
3) I clicked the back button. Fragment A was obtained from backstack, but it again called onCreateView() . This action makes my application a few more problems.
So my question is how to store fragment A in the backstack and not recreate the view.
This method that was used to modify the fragment:
public static void setContent(FragmentManager managerFragment, Fragment detailFragment) { if (managerFragment != null) { if(lastFragment==null && detailFragment instanceof HomeVer3Fragment || (lastFragment!=null && detailFragment instanceof HomeVer3Fragment && lastFragment instanceof HomeVer3Fragment)){ return; } String tag=detailFragment.getClass().getName(); managerFragment.popBackStackImmediate(tag, FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentTransaction ft = managerFragment.beginTransaction(); ft.replace(R.id.content_frame, detailFragment); ft.addToBackStack(tag); ft.commit(); lastFragment = detailFragment; } }
Thanks and sorry for my bad question, my english is not very good.
source share