Questions tagged [fragment-backstack]

Akin to the Android Activity backstack, the Fragment backstack is a task-like stack of Fragments (specified when adding a Fragment to a page with FragmentManager). It allows a linear navigation backwards from the current visible fragment, back through a history of previous fragments in a container until you reach the base fragment.

Akin to the Android Activity backstack, the Fragment backstack is a task-like stack of Fragments (specified when adding a Fragment to a page with FragmentManager). It allows a linear navigation backwards from the current visible fragment, back through a history of previous fragments in a container until you reach the base fragment.

Links

325 questions
130
votes
7 answers

Is this the right way to clean-up Fragment back stack when leaving a deeply nested stack?

I'm using the Android Compatibility library to implement fragments and have extended the layout sample so that a fragment contains a button which fires off another fragment. In the selection pane on the left I have 5 selectable items - A B C D…
PJL
  • 18,057
  • 16
  • 68
  • 66
63
votes
2 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,…
35
votes
3 answers

Navigation popUpTo and PopUpToInclusive aren't clearing the backstack

I'm new to the Android Jetpack Navigation architecture. I'm trying it out on a new app. There's one activity and a few fragments, two of them are login screen and email login screen. I defined those fragments in my navigations XML. The flow of the…
adrilz
  • 365
  • 1
  • 3
  • 8
25
votes
1 answer

What is the difference between enter/exit and popEnter/popExit animations?

In setCustomAnimations() it takes four resource id for the animation. Not really understand them. If someone having clearer picture of it it would be appreciated if you could explain. Let's say having fragment A add in the place holder and…
lannyf
  • 6,775
  • 4
  • 49
  • 92
23
votes
6 answers

How to delete a specific fragment from back stack in android

I have a problem about removing a specific fragment from back stack.My scenario is like this.Fragment-1 is replaced with Fragment-2 and then Fragment-2 is replaced with Fragment-3. Calling order; Fragment-1-->Fragment-2-->Fragment-3. When Fragment-3…
nihasmata
  • 576
  • 1
  • 5
  • 23
22
votes
5 answers

Separate Back Stack for each tab in BottomNavigationView Android using Fragments

I'm implementing BottomNavigationView for navigation in an Android app. I am using Fragments to set the content for each tab. I know how to set up one fragment for each tab and then switch fragments when a tab is clicked. But how can I have a…
20
votes
4 answers

How to get the current fragment displayed in a specific tab of a viewpager?

I want to get the last fragment in the backstack, or the current displayed it's the same for me, in the tab b_1. As you can see in the following image, I have a ViewPager, and another one inner tab b. Thus there are four current fragments…
17
votes
10 answers

PopBackStack but keep the first fragment in android

I am working on fragment transaction, and the backstack is like this: fragA => fragB => fragC => fragD I would like to return to fragA after back fromn the fragD fragD => onBackPress => fragA So, I tried code…
14
votes
2 answers

Architecture Navigation Component : onCreateView gets called every time

Everytime fragment instance is created and reloading when you press back. How to overcome this issue? Inability of having proper backstack in nav controller is a huge productivity issue. Hope it's a missing feature or a work-around made on…
12
votes
7 answers

Android Fragment Back Stack

I have used multiple Fragments in my Project. I want to save a Fragment's state and restore this state when I come back to this. In this Fragment I show multiple images which change on button click. I use the following code for this: String…
12
votes
3 answers

change navigation drawer selected item on fragment backstack change

I have two fragments FragmentHome and FragmentAbout, I have added NavigationDrawer to app when I click Home it opens FragmentHome and About opens FragmentAbout, when I open FragmentAbout I am also adding it to backstack. This is working fine. Now…
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,734
  • 1
  • 13
  • 35
9
votes
1 answer

Android Navigation Component - Navigate up opens the same fragment

I'm having a problem where when executing findNavController(R.id.main_nav_host).navigateUp() or findNavController(R.id.main_nav_host).popBackStack() Instead of going back to the last fragment in the backstack, it reopens/navigates to the…
8
votes
3 answers

How to add BackStackEntry to BackStack if not exists

I've added custom keyboard to my Fragment and now I want to implement closing keyboard when on back pressed. class CustomKeyboard { public void init(Context context) { //... FragmentManager fragmentManager = ((Activity)…
Yuliia Ashomok
  • 7,177
  • 1
  • 53
  • 59
8
votes
6 answers

Is there anyway to swap or reorder fragment BackStack entry?

am creating multiple fragment app, which require easy changing of fragment tabs, whose BackStack entry must be kept. On user click fragment must be pop up immediate. I think reordering BackStack is the best option. Do anyone know how to reorder…
user6318834
1
2 3
21 22