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
7
votes
1 answer
How to add/remove Fragment on Button click?
At present I have got a "RELATIVE_LAYOUT" container which I am using for adding my fragment.
I am using OnClickListener on a button to load the fragment XML layout into the RelativeLayout container.
What I want to achieve is that when I press the…

Abhi9
- 320
- 1
- 2
- 13
7
votes
0 answers
Save & restore Fragment's UI state when pushed and popped out of the backstack
Background:
I have a main Activity, it wraps a main Fragment that can be changed, and in order to keep a backstack I use FragmentManager's backstack.
The main difference from keeping an activity stack is that when a fragment is pushed to the…

ndori
- 1,934
- 1
- 18
- 23
6
votes
1 answer
Why I am getting "Cannot remove Fragment attached to a different FragmentManager" in Android?
I am trying to remove a fragment but very rarely on Crashlytics I am able to see a bug java.lang.IllegalStateException: Cannot remove Fragment attached to a different FragmentManager.
I have a separate fragment for fetching user's current location.…

Prashant Jha
- 574
- 6
- 21
6
votes
0 answers
Avoid IllegalStateException when doing popBackStackImmediate during onResume in fragment
I have a single Activity with fragments and two simple methods inside the activity for managing fragments: pushFragmentImmediate() and popFragmentImmediate().
public void pushFragmentImmediate(Fragment fragment) {
FragmentTransaction transaction…

Erik Sillén
- 337
- 2
- 13
6
votes
1 answer
Get access to getSupportFragmentManager in non activity class
I hope someone can help.
I have a non activity class in which I need to access the fragmentmanager in a static method, unfortunatly I don`t know how to pass the context correctly.
Any help is appreciated,
Non activity class:
public class testClass…

Simon
- 1,691
- 2
- 13
- 28
6
votes
1 answer
getFragments method returns only 1 fragment when using replace transactions, used to return all
As of SDK 26.0.0-beta1 and above, making use of the getFragments https://developer.android.com/reference/android/support/v4/app/FragmentManager.html#getFragments() method returns a list with only 1 fragment and the size of the list is also always 1…

user18715
- 61
- 3
6
votes
3 answers
How to save state in fragment
I have 4 button to replace fragment in activity [fragment A , fragment B , fragment C , fragment D] and then I replace fragment A to activity and I change value in fragment A after that I replace fragment B to fragment A and replace fragment C to…

Wuttipong Khemphetjetsada
- 561
- 3
- 8
- 18
6
votes
7 answers
Fragment - getArguments() returns an empty bundle
Hope somebody can help me to understand this:
I am using a single-activity app and lots of Fragments that are replaced in the same container, and I am testing my app in a real device with the "Don't keep activities" option enabled
When a new…

allo86
- 946
- 1
- 9
- 23
6
votes
3 answers
How to keep the same fragment when activity restarts due to orientation change in a Navigation Drawer Activity
I found many post explaining how get the Fragment from the savedInstanceState Bundle but, because the Activity can swap between 4 Fragments, i need a way to know which Fragment was alive before rotate when the orientation started to change.
The…

MiguelSlv
- 14,067
- 15
- 102
- 169
6
votes
1 answer
Is there ever a good reason to use the Child Fragment Manager for DialogFragments?
Normally when showing a DialogFragment from an Activity, you do this:
MyDialogFragment myDialogFragment = MyDialogFragment.newInstance(args);
myDialogFragment.show(getSupportFragmentManager(), MY_TAG);
Or if you are in a Fragment, you…

user6293261
- 61
- 4
6
votes
1 answer
How to clear fragmentManager back stack without poping fragments?
Simple question but seems impossible to answer...
How to clear fragmentManager back stack without poping fragments?
I understand it like this:
Back stack entries = list of previosly saved transactions with addToBackStack command.
For example:…

Daniel Więcek
- 625
- 1
- 10
- 16
6
votes
3 answers
How to squash fragments on the backstack which match by their fragment tag?
The layout of my Android tablet app consists of a list of items and a details view. When a list item is selected the associated content is displayed in the details view.
+--------+-------------+
| Item 1 | |
+--------+ Item |
|…

JJD
- 50,076
- 60
- 203
- 339
6
votes
2 answers
getSupportFragmentManager doesn't compile on DialogFragment
How can I show this :
public class TagsDialog extends DialogFragment
{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
…

sprocket12
- 5,368
- 18
- 64
- 133
6
votes
1 answer
How can I implement FragmentManager and FragmentTransaction to replace just a single fragment?
I have an activity with 3 fragments; a header; a body; a footer (same point as in HTML). The bodyfragment contains three buttons which each should replace the middle fragment (body; itself) with another one, but I can't figure out how to work…

Carl
- 249
- 2
- 5
- 13
5
votes
1 answer
PreferenceFragments not in the same FragmentManager?
We have a PreferenceFragmentCompat, and with a tap on a preference, we want to switch from the current PreferenceFragmentCompat to a new PreferenceFragmentCompat. (To have certain settings on a new screen).
However, regardless of what we have tried,…

Kyu96
- 1,159
- 2
- 17
- 35