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
8
votes
1 answer
findFragmentByTag null for Fragment A, if setRetain(true) on Fragment B
My problem involves an activity hosting three support fragments. One is a normal programmatic fragment (let's call it a home fragment). One is a portrait fragment added on top of the home fragment when the device is orientated, and one is…

Daniel Wilson
- 18,838
- 12
- 85
- 135
8
votes
2 answers
Android fragment implementation issue
Here's my xml for my fragment:

Jon Sansoucie
- 521
- 4
- 18
8
votes
6 answers
How to avoid adding same fragment to stack
I need some help. em adding fragment to activity this way. problem is on each call of openFragment it create fragment and add. which is obvious. Question: what modification i do, so it can add fragment only once. on the next call with same fragment…

Mohsin
- 1,586
- 1
- 22
- 44
8
votes
2 answers
Android: master/detail flow (dual-pane) using 1 activity
As reported by the Android guide, dual-pane can be achieved in two ways:
Multiple fragments, one activity
Multiple fragments, multiple activities
I am using the first case (the Android guide only explains the second case).
This is what happens on…

Daniele B
- 19,801
- 29
- 115
- 173
8
votes
4 answers
android.support.v4.app.FragmentManager OR android.app.FragmentManager?
I'm learning Android development. I get stuck at something that should be very easy.
Im creating an App with one Activity, 2 fragments and 1 interface.
android:minSdkVersion="11"
android:targetSdkVersion="19
So in the main activity Im trying to…

Foo
- 596
- 2
- 5
- 21
8
votes
1 answer
BetterPickers without a support library
I am using https://github.com/derekbrameyer/android-betterpickers to use time- and date pickers for my app. However, my app does not need a support library and it seems like I need SupportFragmentManager when setting a FragmentManager to the Time-…

vandus
- 3,248
- 3
- 30
- 44
8
votes
1 answer
Android: remove() Fragment--> add() new Fragment of same class again ->onCreateView and onActivityCreated not called?
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:

user2212461
- 3,105
- 8
- 49
- 87
8
votes
2 answers
Fragment not calling onPause or onStop when using replace
I have this odd problem that my fragments are not calling any of the end lifecycle methods like onPause and onStop when I replace it with another fragment.
I replace the fragment like this
public static void replaceFragment(Activity activity, int…

JWqvist
- 717
- 6
- 15
7
votes
1 answer
FragmentManager is already executing transactions viewpager2
I am using 4 fragments with view pager 2.
And got this error suddenly. The crash does not always appear. I have searched other problems but I could not find any solution about viewpager2.
crash report from mobile could not get the full…

Niaz Sagor
- 83
- 1
- 4
7
votes
3 answers
FragmentManager has been destroyed
EDIT: It seems that this only happens if my previous activity is in landscape, and the setRequestedOrientation() is portrait, what could possibly be the problem?
I have a code in an activity, which starts a Volley request to a REST API to retrieve…

Lee Boon Kong
- 1,007
- 1
- 8
- 17
7
votes
3 answers
How to get previous fragments?
In order to reuse some fragments in my app, I need to know which Fragment is the second on the back stack.
In order to do that I'm using getFragmentManager().getFragments(), which shows the following error (but works!)
FragmentManager.getFragments…

kike
- 4,255
- 5
- 23
- 41
7
votes
2 answers
How to listen to Fragment Backstack Pop only?
I wanted to know when a Fragment has been pop from backstack.
I have my code as below
private void setupChildFragmentPopListener() {
getChildFragmentManager().addOnBackStackChangedListener(
new…

Elye
- 53,639
- 54
- 212
- 474
7
votes
2 answers
How do I know if onSaveInstanceState() has been called so that I can avoid the IllegalStateException?
When a user selects an item in the Navigation Drawer, my app kicks off a Handler which, after waiting for the drawer to close, calls the code to replace the fragment in my main Activity. However, if the device has been rotated during the delay, I…

NSouth
- 5,067
- 7
- 48
- 83
7
votes
2 answers
Fragments overlapping with DrawerLayout/NavigationView
Using a DrawerLayout with a NavigationView and a FrameLayout I want to switch Fragments. That works great.
However, if I switch too quickly, then the Fragments overlaps...
It is like executePendingTransactions() does not…

shkschneider
- 17,833
- 13
- 59
- 112
7
votes
3 answers
Replacing fragments in an activity not calling onAttach, onCreate, onCreateView, etc
So I have this piece of code here, I am creating a new Fragment and replacing it with another fragment. That works well. However I have notice that on the first line the constructor is being called but the onAttach(), onCreate() etc are not. If I…

Castaldi
- 671
- 8
- 20