FragmentManager is an interface for interacting with Fragment objects inside an Activity in Android. While the FragmentManager API was introduced in HONEYCOMB, a version of the API at is also available for use on older platforms through FragmentActivity. For more information about using fragments, read the Fragments developer guide.
Questions tagged [fragmentmanager]
700 questions
11
votes
3 answers
FragmentTransaction hide/show doesn't work sometimes
I have an activity with bottom navigation tabs that are changing the fragments in it. When I click back and forth on those tabs, at some point it stops working. Code executes just fine as I put some logs in it. But the fragments aren't being…

Jacek Kwiecień
- 12,397
- 20
- 85
- 157
10
votes
2 answers
Manage Fragment Backstack Flow without flicks
I have created an AppCompatActivity Opened fragment A->B->C->D->E->F
with replace()
I am on F which contain button when I press the
button I want to clear Fragments up to C and Want to open G on top of C so new Sequence will be A->B->C->G.I can…

Kirtan
- 1,782
- 1
- 13
- 35
10
votes
5 answers
What should I use in place of getWidth() and getHeight() to know when width is greater and when height is greater
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Display;
import…

Ankit
- 271
- 3
- 11
10
votes
2 answers
onBackStackChanged() called twice when new fragment is added in backstack
So, i have notice interesting problem. When i add new fragment programmatically, method onBackStackChanged from OnBackStackChangedListener is called twice, but it must be call only one time. Here is my code of activity:
import…

Alex D.
- 1,424
- 15
- 40
10
votes
2 answers
onViewCreated - wrong place to replace fragment?
I'm showing an empty fragment if the user has no data. In that emptyFragment (in onViewCreated) I check for a condition and sometimes would like to replace that empty Fragment with another one, so I call a method on the according activity which…

swalkner
- 16,679
- 31
- 123
- 210
10
votes
0 answers
FragmentManager.getFragmens().size() dont decrease after FragmentTransaction.remove(Fragment)
After a while searching the reason of my NPE, i noticed that despite FragmentTransaction.remove(Fragment) reallys removes the Fragment, the size of the List returned by FragmentManager.getFragments() still the same.
This screenshot shows what is…

Informatheus
- 1,025
- 1
- 9
- 20
9
votes
2 answers
Cannot setMaxLifecycle for Fragment not attached to FragmentManager: ViewPager
I have tried with so many given examples but nothing worked for me. When I am trying to remove a page dynamically from viewPager then I am getting exception:
Cannot setMaxLifecycle for Fragment not attached to FragmentManager
My PagerAdapter is…

Anupriya
- 1,663
- 3
- 17
- 28
9
votes
1 answer
what to replace deprecated getFragmentManager() method with (API 28)?
I have an Android application I've been working on, min sdk = 21. In it, I use a custom PreferenceActivity that in turn calls a PreferenceFragment. However, after recently updating to API 28, I noticed that the getFragmentManager() method has been…

Peter Mghendi
- 171
- 1
- 7
- 11
9
votes
6 answers
How to get NavHostFragment
I'm integrating Android's Navigation Architecture Components into my app. I ran into some problems with passing data to the start of a fragment from an activity, so I was following this answer: Navigation Architecture Component- Passing argument…

Saba Imran
- 201
- 2
- 11
9
votes
4 answers
Android: Fragment manager becomes null
I am getting crashes for my app. Basically, I have a fragment in which a dialog has to be displayed in one scenario. I had created dialog by extending dialog fragment. The problem is for some users it crashes throwing null pointer exception.
This…

Nitish
- 3,097
- 13
- 45
- 80
9
votes
3 answers
Check if a fragment exists and reuse it
I'm using the following code to create a fragment everytime the user click on an item in a list view.
But in this way the fragment is created at every user click. What I want is to reuse the old fragment (if it exists) and only reload its content…

Usi Usi
- 2,967
- 5
- 38
- 69
9
votes
1 answer
Fragment with ViewPager inside Fragment and FragmentStatePagerAdapter results in Exception (with complete example)
I have a simple Fragment with a ViewPager.
I'm using the up to date support library, v4 rev18!
If I show the sub fragment the first time, everything works fine, if I go back and show it again, the app crashes with the following exception:
I have a…

prom85
- 16,896
- 17
- 122
- 242
8
votes
1 answer
Android crash onCreate() - Fragment cannot be cast to androidx.navigation.fragment.NavHostFragment
I decided to execute a Firebase Robo Test for my app and noticed that it always crashes after opening an external activity and then returning back to the app. I was able to duplicate the problem by enabling the "Don't keep activities" in the…

Miha M
- 379
- 1
- 3
- 14
8
votes
4 answers
Jumping scrolling when switching fragments
Inside a ScrollView I am dynamically switching between two fragments with different heights.
Unfortunately that leads to jumping. One can see it in the following animation:
I am scrolling down until I reach the button "show yellow".
Pressing "show…

stefan.at.kotlin
- 15,347
- 38
- 147
- 270
8
votes
0 answers
React Native : add fragment to mainactivity using Android Native Modules
I have a specific Android native library to integrate the camera features. The library provides the Fragment with the all it features. I just want to integrate that with Mainactivity in React Native app.
I have followed the link "Add fragment into…

Praveen
- 90,477
- 74
- 177
- 219