The fragment which is got from backstack, call onCreateView() again

Viewed 5510

Please help me resolve my issue.

I have MainActivity with a framelayout. I want to replace some fragments into the framelayout. Now I am encounering an issues, it's:

1) I created and put fragment A to framelayout. Fragment A called onCreateView...etc.

2) Then I created and put fragment B to layout... Fragment A was put on backstack and it called onPause() (not called onDeattach(), onDestroy...)

3) I pressed back button. Fragment A was got from backstack, but it called onCreateView() again. This action make my app has some another issues.

So my question is how to store fragment A in backstack and it don't recreate view.

This's the method that was used to change 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;
    }
}

Thank and sorry for my bad question, my english is not well.

1 Answers
Related