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
18
votes
1 answer
Android: How to prevent lag or animation skip on Fragment transaction when inflating RecyclerView inside?
I am working with some fragments but the transition animations when switching from one to another is very laggy and sometimes it even skips the entire animation (which I've read that sometimes is an outcome of poor fragment performance).
The very…

M'aiq the Coder
- 762
- 6
- 18
17
votes
5 answers
How to call fragment method from main activity
I have method in fragment class. I want to call that method from main activity but I don't want to use FragmentById (or) FragmentByTag.
My fragment method:
public void setItemFromDrawer(String sourceTag, String destTag) {
//dosomething
}
How to…

hikoo
- 517
- 4
- 10
- 20
17
votes
6 answers
FragmentManager popBackStack doesn't remove fragment
I'm implementing menu navigation using Fragments. So I begin with Home, and then users can navigate to diferent sections and details of each section.
When a user changes section, then I call pop on the fragmentmanager backstack until I reach Home,…

edrian
- 4,501
- 5
- 31
- 35
16
votes
4 answers
android.view.AbsSavedState$1 cannot be cast to android.widget.CompoundButton$SavedState
I am seeing the following error on Crashlytics with a lot of incidences:
Caused by java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.CompoundButton$SavedState
at…

M Rajoy
- 4,028
- 14
- 54
- 111
16
votes
4 answers
How to restore fragment back stack with in an activity (After application is killed in background)
In an Android app-
Say I am in an Activity - MyActivity which holds one Fragment at a time.
First I loaded Fragment A to it (With no tags I added it to back stack of the FragmentManager)
Then at some point I loaded Fragment B (Again with no tags I…

Arun C
- 9,035
- 2
- 28
- 42
16
votes
3 answers
popBackStack causes calling oncreateView of fragment again and again
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();
…

Anshul
- 9,312
- 11
- 57
- 74
15
votes
3 answers
androidx getFragmentManager() has been deprecated
Getting deprecation warnings for androidx.fragment.app.Fragment:
warning: [deprecation] getFragmentManager() in Fragment has been deprecated.
What to do?

Martin Zeitler
- 1
- 19
- 155
- 216
14
votes
4 answers
setFragmentResult doesn't work onClick listener
hello my problem is the following, I have 2 fragments, one receives with SetFragmentResultListener and another sends with setFragmentResult
The problem is that setFragmentResult does not work inside an OnClickListener but it does work…

Sebastian Labadie
- 141
- 1
- 1
- 4
14
votes
2 answers
Android onBackStackChanged() not called
I have an Activity like the code below:
public class AuthenticatedMainActivity extends Activity implements FragmentManager.OnBackStackChangedListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
.............
…
user3491420
14
votes
2 answers
How to remove previous back stack entry from FragmentManager?
I have an activity in which I am switching fragments using following method:
public void setCurrentFragment(Fragment fragment) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
…

nemezis
- 536
- 1
- 6
- 21
13
votes
1 answer
Is it safe to commit a FragmentTransaction inside onActivityResult()?
Years ago, I ran into a problem in one of my apps when I tried to commit a FragmentTransaction inside my onActivityResult() callback. Googling around, I found this question and answer, which say
At the time that onActivityResult() is called, the…

Ben P.
- 52,661
- 6
- 95
- 123
13
votes
2 answers
How to handle multiple fragment interaction listeners in one Activity properly?
I have one Activity and six different Fragments attached to it. Each fragment has OnFragmentInteractionListener interface and activity implements all these listeners in order to receive callbacks. It looks a little messy, so I'm interested are there…

MainstreamDeveloper00
- 8,436
- 15
- 56
- 102
13
votes
2 answers
How to set a Tag to a Fragment in Android
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…

CBA110
- 1,072
- 2
- 18
- 37
12
votes
3 answers
Where to call getChildFragmentManager()?
Problem
According to the Google's docs:
You can now embed fragments inside fragments. This is useful for a
variety of situations in which you want to place dynamic and re-usable
UI components into a UI component that is itself dynamic and
…

AlexMomotov
- 7,418
- 8
- 24
- 34
11
votes
3 answers
Fragment already added, dialogfragment?
I have a dialogfragment which displays fine but some time when I try to display it I keep getting IllegalStateException
Below is the logcat
java.lang.IllegalStateException: Fragment already added: SelectPlan04Dialog{fa768dc #7 }
at…

WISHY
- 11,067
- 25
- 105
- 197