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
211
votes
22 answers
How can I access getSupportFragmentManager() in a fragment?
I have a FragmentActivity and I want to use a map fragment within it. I'm having a problem getting the support fragment manager to access it.
if (googleMap == null) {
googleMap = ((SupportMapFragment) getSupportFragmentManager()
…

DjP
- 4,537
- 2
- 25
- 34
105
votes
7 answers
FragmentPagerAdapter deprecated
Since API 27 FragmentPagerAdapter is deprecated. What's the best alternative to use for this?
In my case, I understand something like super(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) would need to be used, but I don't know where within…

wbk727
- 8,017
- 12
- 61
- 125
66
votes
3 answers
Android FragmentManager BackStackRecord.run throwing NullPointerException
I sometimes get the following exception when working with Fragments:
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:591)
at…

NickL
- 4,258
- 2
- 21
- 38
65
votes
3 answers
What does FragmentManager and FragmentTransaction exactly do?
I have simple code below
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container,…

Alireza.Heidari
- 737
- 1
- 8
- 11
64
votes
3 answers
onAttach() not called in Fragment
My Fragment doesn't call onAttach(context) method when it launched from AppCompatActivity.
Fragment creating in XML:

winston
- 875
- 1
- 8
- 15
44
votes
8 answers
Checking if state is saved before committing a FragmentTransaction
I sometimes see the following stacktrace for a commit that can happen when the user isn't looking at the activity (after state's been saved):
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at…

hwrdprkns
- 7,525
- 12
- 48
- 69
41
votes
2 answers
Cannot resolve method 'show(android.support.v4.app.FragmentManager, java.lang.String)
For some reason when I try to show a Dialog I get an error from dialog.show(fm, DIALOG_DATE); saying Cannot resolve method 'show(android.support.v4.app.FragmentManager, java.lang.String)'
Why can't it resolve the method?…

MasterProgrammer200
- 1,021
- 2
- 17
- 29
35
votes
5 answers
An invisible layout behind the fragment is getting clicked:
I have created several fragments and I add the first fragment the following way:
mainFragment = (MainFragment) MainFragment.create();
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.slide_in_right,…

Emil Adz
- 40,709
- 36
- 140
- 187
26
votes
8 answers
getBackStackEntryCount() always returns 0 even after adding addToBackStack and executePendingTransactions()
I have two activities A and B. Activity A has a mapFragment and I am adding it to backstack. When I come back from to Actvity A from B, I want the fragment to show up in same state as I left it. But getFragmentManager().getBackStackEntryCount() is…

user3555350
- 261
- 1
- 3
- 4
24
votes
11 answers
Backstack management : Restarter must be created only during owner's initialization stage
I am using a bottom navigation bar in my MainActivity to handle some fragments. This is the code used for switching between them:
private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
if…

Gabi
- 667
- 1
- 7
- 17
23
votes
3 answers
Passing data back to previous fragment from current fragment
I am Using Navigation Drawer in my app. I have one MainActivity and rest of are Fragments. So the issue is Suppose i have three fragments like A,B,C.
Now in A i have one button and i am sending data from A>B.
For example putSring("datafrom…

chris
- 699
- 4
- 12
- 35
23
votes
1 answer
Proper use of sub sub fragments with (Child)FragmentManager
How do I properly use Fragments in Fragments?
My (simplified) use case is following, I have an activity with a layout fragment and this fragment theirself contains a sub fragment... all fragments are added manually to their…

prom85
- 16,896
- 17
- 122
- 242
21
votes
5 answers
Ignoring navigate() call: FragmentManager has already saved its state
I'm using navigation in MainActivity, then I start SecondActivity (for result). After finish of SecondActivity I would like to continue with navigation in MainActivity, but FragmentManager has saved his state already.
On…

Francis
- 6,788
- 5
- 47
- 64
21
votes
6 answers
Fragment must be a public static class to be properly recreated from instance state
After updating to the latest support repository,
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:percent:24.2.0'
compile 'com.android.support:recyclerview-v7:24.2.0'
I'm…

Falling Into Infinity
- 697
- 3
- 13
- 34
18
votes
5 answers
java.lang.IllegalStateException: FragmentManager has been destroyed
In activity onResume method I call volley request, which is getting list of items and then loads them to ListFragment inside this activity. When I enter activity for the first time everything is working correctly, but when I re-enter activity the…

Sergey Roytman
- 303
- 1
- 2
- 9