fragmentmanager

popBackStack causes calling oncreateView of fragment again and again

南楼画角 提交于 2020-03-18 03:43:17
问题 I have 3 fragment A, B,C.I wrote piece of code for replacing them and maintaining backstack: public void addFragment(Fragment fragmentToAdd, String fragmentTag) { FragmentManager supportFragmentManager = getSupportFragmentManager(); Fragment activeFragment = getActiveFragment(); FragmentTransaction fragmentTransaction = supportFragmentManager .beginTransaction(); if (null != activeFragment) { fragmentTransaction.hide(activeFragment); } fragmentTransaction.replace(R.id.layout_child_activity,

OnResume called multiple times inside fragment

怎甘沉沦 提交于 2020-01-24 10:33:06
问题 I have InnerFragment containing RecyclerView, inside MainFragment which is added to ViewPager . When MainFragment gets created while swiping OnResume is called multiple times 1st time : OnResume called once in MainFragment and Once in InnerFragment 2n time : OnResume called once in MainFragment and Twice in InnerFragment 3rd time : OnResume called once in MainFragment and Thrice in InnerFragment Adding MainFragment in ViewPager //Assigning Adapter in ViewPager mViewPager.setAdapter(new

OnResume called multiple times inside fragment

為{幸葍}努か 提交于 2020-01-24 10:33:05
问题 I have InnerFragment containing RecyclerView, inside MainFragment which is added to ViewPager . When MainFragment gets created while swiping OnResume is called multiple times 1st time : OnResume called once in MainFragment and Once in InnerFragment 2n time : OnResume called once in MainFragment and Twice in InnerFragment 3rd time : OnResume called once in MainFragment and Thrice in InnerFragment Adding MainFragment in ViewPager //Assigning Adapter in ViewPager mViewPager.setAdapter(new

FragmentPagerAdapter deprecated

℡╲_俬逩灬. 提交于 2020-01-22 17:12:56
问题 Since API 27 FragmentPagerAdapter is deprecated. What's the best alternative to use for this? In my case, I understand some thing like super(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) would need to be used, but I don't know where within my code this needs to go. I got these imports in my class: import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentPagerAdapter but FragmentPagerAdapter in class MyViewPagerAdapter(manager: FragmentManager) :

Android using both getFragmentManager and getSupportFragmentManager causes overlapping

戏子无情 提交于 2020-01-21 10:14:07
问题 I have something like this inside my activity: @Override public void onNavigationDrawerItemSelected(int position) { Fragment fragment = null; switch (position+1) { case 1: { fragment = new Fragment_Login(); FragmentManager frgManager = getFragmentManager(); frgManager.beginTransaction().replace(R.id.container, fragment) .commit(); break; } case 2: { SwipeRefreshListFragment swipeFragment = new Fragment_List_Of_Assessments(); FragmentTransaction transaction = getSupportFragmentManager()

Android: remove() Fragment--> add() new Fragment of same class again ->onCreateView and onActivityCreated not called?

不问归期 提交于 2020-01-21 03:15:47
问题 I am destroying a programmatically created fragment with: getFragmentManager().beginTransaction().remove(getFragmentManager().findFragmentById(R.id.test)).commit(); Which is determined in the xml file like this: <LinearLayout android:id="@+id/test" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> </LinearLayout> If I then create a fragment from the same class again in the mainactivity: getSupportFragmentManager().beginTransaction() .add

Android: remove() Fragment--> add() new Fragment of same class again ->onCreateView and onActivityCreated not called?

爱⌒轻易说出口 提交于 2020-01-21 03:15:20
问题 I am destroying a programmatically created fragment with: getFragmentManager().beginTransaction().remove(getFragmentManager().findFragmentById(R.id.test)).commit(); Which is determined in the xml file like this: <LinearLayout android:id="@+id/test" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> </LinearLayout> If I then create a fragment from the same class again in the mainactivity: getSupportFragmentManager().beginTransaction() .add

instantiateItem nor getItem are called on FragmentPagerAdapter

a 夏天 提交于 2020-01-16 00:27:06
问题 I've one activity with a viewpager with a custom FragmentAdapter. Here is my adapter code: this.viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) { SparseArray<WeakReference<Fragment>> registeredFragments = new SparseArray<>(4); @NonNull @Override public Object instantiateItem(ViewGroup container, int position) { Fragment fragment = (Fragment) super.instantiateItem(container, position); this.registeredFragments.put(position, new WeakReference<>(fragment)); return

How to set a Tag to a Fragment in Android

痴心易碎 提交于 2020-01-13 07:59:09
问题 I've looked at all the questions on Stackoverflow but could not find a single definitive answer to this question. How do you set a Tag to a Fragment so that you can retrieve it via getFragmentManager().findFragmentByTag() ? Could someone give a simple code example of how to create a tag to a Fragment ? 回答1: You can set a Tag during fragment transaction. For example if it's a replace transaction you could do it like so: FragmentManager fragmentManager = getSupportFragmentManager();

Save state of fragments in backstack

为君一笑 提交于 2020-01-03 13:40:09
问题 My problem is generally described in this question: Once for all, how to correctly save instance state of Fragments in back stack? But i can't understand how the accepted answer is related to it. To keep it short: There are 2 fragments A and B. I go from A to B using transaction.replace() and add transaction to backstack. I rotate screen -> fragment A is not visible, but it's onSaveInstanceState is called - everything ok up to this point. I rotate screen again. Again A's onSaveInstanceState