Snippet retrieved from backstack, call onCreateView () again

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.

+6
source share
1 answer

check out my full post here Dynamically changing fragments inside the fragment tab host?

As far as you know that you are rebooting (I suppose), you can do something like below:

(1) Initiate a boolean say

 boolean android_hacker = false; 

(2) Now tell U to get the data and create some view using the list view. Now at this point set "android_hacker = true"; after you have extracted all the data.

(3) Now when U returns to the same fragment again, say β€œFragmentA” and then check the OnCreateView value as indicated.

 if(android_hacker != true){ new GoAsyncTask().execute(); }else{ // Perform stuff U need } 

What is it. Hope this helps someone.

+2
source

All Articles