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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
10 views

How avoid the backstack entries in dialog fragment

am using the viewpager in order show the frgment with dynamic data , whenn the particular time opem the dialog the exiting support fragment manger back stack entry cleared and created the new back ...
IYANAR D's user avatar
0 votes
2 answers
48 views

Is there a way to load a fragment from the back stack using the Navigation Component?

I have a number of custom tabs, and I want the NavController to load a fragment from the back stack if it exists when the user navigates between tabs. I check if a fragment exists in my back stack, ...
Ghazal's user avatar
  • 163
0 votes
0 answers
27 views

how to fix a toolbar bag (Android, kotlin)

I have problem with backstack and toolbar. I have a singchat fragment and a user overlay. When I switch from the singchat fragment to the user overlay, I disable the mToolbar that is passed to all ...
insideggg's user avatar
0 votes
0 answers
179 views

Handling Back stack Navigation in Compose

I have a question regarding compose navigation. I have Activity A which is child to other activity. Activity A has a composable view to set to the content. Now from A have to navigate to a fragment B ...
hamza khan's user avatar
0 votes
1 answer
23 views

Close Dialog from Activity open in Child Fragment in NavGraph

I want to close any dialog open from nav_graph on some event. NavHostActivity.kt xml <fragment android:id="@+id/fragment" android:name="androidx....
Taimoor Khan's user avatar
0 votes
1 answer
34 views

Android navigation drawer layout menu item fragments not getting added to back stack

I've got a bug that I think may be unsolvable. I'm not sure what I am doing wrong; and I suspect that perhaps I am not doing things in the correct, 'android' way. I have a single activity app with ...
user1743524's user avatar
0 votes
0 answers
14 views

when onBackPress happens in fragments app will close

I made some fragments and a nav_Graph and using setOnClickListener on some button and actions from nav_Graph to move between the fragments but when I press the back button it will close the app how ...
BigBeast DGX's user avatar
1 vote
2 answers
52 views

3rd Fragment override 1st on backPress, when don't use addToBackStack in 2nd fragment

I open fragments like this: [1]+with addToBackStack) > [2](without addToBackStack) > [3] in Fragment 3 when click onBackPress Button then 2nd is not visible but 3rd override 1. If I use ...
TexD's user avatar
  • 194
0 votes
0 answers
33 views

Replacing fragment not working in Android and error is ' view not found '

I am trying to replace fragments on back press but unable to do so as error pops out " view not found " . I am using Drawer layout as my parent layout in MainActivity.xml as shown in image. ...
Abhas Sharma's user avatar
0 votes
1 answer
20 views

How to return to the last fragment after pressing home button or exit the android app?

when returning to the app after pressing home button or exit the app it returns to the first fragment of the app (splash screen) I need it to return to the last fragment before pressing home button, ...
Alaa Hosnii's user avatar
0 votes
2 answers
42 views

How to call a method in a Fragment when backstack change

I have 2 fragments FragmentA and FragmentB From FragmentA I open FragmentB val transaction = fragmentManager.beginTransaction() transaction.add(CONTAINER_VIEW_ID, FRAGMENT_B_INSTANCE, FRAGMENT_B_TAG) ...
AndroidDev's user avatar
0 votes
2 answers
1k views

java.lang.IllegalArgumentException: Navigation action/destination

I'm building a notes application. I want to save the note when user press the back button from the createsNotesFragment and finish the createNotesFragment so that I can move to the homeFragment. The ...
Navneet's user avatar
  • 77
0 votes
1 answer
176 views

How to handle back-stack in Fragment?

case 1: I have 3 fragments A,B,C. When I am moving from A->B->C and then by pressing a save button on C fragment , I come back to fragment B and now when I press the back button at this point (...
Geetika's user avatar
  • 25
0 votes
0 answers
40 views

Android Navigation Component (State retained)

I am facing an issue with bottom navigation when navigating through different fragments, There are 3 fragments as follows: List, Loading & Playing When user taps on Lists, it has to go to loading ...
h_malik's user avatar
  • 167
1 vote
0 answers
92 views

"Deep-link" to a fragment while using the app - Navigation Component

Suppose for simplicity that an App consists of 3 screens (Home, Account, Payments) and these are hosted inside a Navigation Graph. When pressing a button in Home screen, user navigates to Account ...
Fivos's user avatar
  • 568
1 vote
1 answer
297 views

How to fix OnBackPressedCallback if it doesn't work in Fragment?

Here I override handleOnBackPressed() method: Log.d("Fragment", "onViewCreated") requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner) { ...
Viktor's user avatar
  • 23
1 vote
1 answer
507 views

Navigation Component: How to pop back to previous destination after navigate to a destination using deep link?

I navigate to a destination using deep link in another navigation graph Navigation.findNavController(view).navigate(Uri.parse(link)); And I just want to return to the previous destination. However, ...
Howard Lau's user avatar
0 votes
1 answer
325 views

How to set in Android to be navigated to the same fragment every time from the bottom navigation bar?

I have 4 fragments: A, B, C and X. A, B and C are found on the bottom navigation bar, so every time I click on item A, I get the A fragment on the screen, click on B, I get B. When I click on C, I ...
Antal Georgina's user avatar
0 votes
1 answer
205 views

Fragments are getting destroyed when back pressed. I want it to be not destroy when back press so that I can save the states of fragments

I created an Activity and added 3 fragments into it. One is HomeFragment, second is ProductDetailFragment, and third is CartFragment. I have added multiple quantities of a product from ...
Abhas Sharma's user avatar
0 votes
1 answer
44 views

how to not detsroy the fragments opened when switching with bottom navigation buttons

In the belowcode, we have a TrendsFragment and a ProfileFragment as base fragments that will be opened with bottom navigation view. I can open a Blank Fragment and navigate to it from both of these. ...
yusufff's user avatar
1 vote
1 answer
294 views

Android onBackPressed adds Fragment instead of replacing

In my app, I have a TopActionBar fragment that is loaded on the MainActivity that loads a MaterialToolbar, along with my navigation drawer. I have a FrameLayout in this fragment that I replace with ...
Connor Smith's user avatar
0 votes
1 answer
207 views

How to get top Fragment in backstack from DialogFragment

I'm using navigation to navigate between fragments. And I have a DialogFragment, it can called from from many fragment like this: val dialog = FragmentDialog dialog.show(childFragmentManager, "...
ninhnau19's user avatar
  • 734
0 votes
1 answer
71 views

I have multiple fragments.I want to save all Instances in backstack till the home button pressed again

I tried many methods to save instances but I am confused how to save instances in backstack because no one described how to use it if there multiple fragments.my code in mainactivity below: ...
Aparichit_Coder's user avatar
1 vote
1 answer
63 views

How do I implement that a fragment doesn't get saved onto the backstack?

I work on an app and this app has a list fragment as the starting point when you open the app. Now when I click on a listItem an update fragment opens and when you press the save button you go back to ...
nikenzo's user avatar
  • 13
0 votes
2 answers
47 views

How can I write a single function that can be re-used by multiple fragments to navigate to a singular destination?

Let's say I have 4 fragments and navigate through them in the order A -> B -> C -> D using a NavController object. A is my home screen. I'd like to write a single function called goToA() that ...
Kun.tito's user avatar
  • 185
0 votes
1 answer
695 views

Android. How to avoid fragment be recreated when back from another fragment?

I'm using MVP in my project. I have an activity. Inside this activity I'm showing fragment. Fragment contains some data, edit text, buttons etc. From this fragment it is possible to navigate to ...
testivanivan's user avatar
  • 1,114
1 vote
0 answers
147 views

Why `supportFragmentManager.backStackEntryCount` is empty after `add()` fragment to stack

In Android app (Kotlin) I have Activity with container what have fragment A in it. On user interaction, I am adding fragment B to container by: supportFragmentManager.commit { add(container, ...
Baterka's user avatar
  • 3,195
0 votes
0 answers
697 views

How to manage scroll states with Jetpcak compose?

Single activity has three screens, S1(User List) -> LazyColumn S2(FormA) -> Column(Scrollable) S3(FormB) -> Column(Scrollable) Below are four possible scenarios of visiting screens with ...
Chitrang's user avatar
  • 5,107
0 votes
1 answer
2k views

Keep ViewModel instance when navigating back with by navGraphViewModel

So I am following Google's approach where you use single activity for the whole app and multiple view models, which are scoped to your nested nav graphs or fragments. And I have a problem with this ...
MrArtyD's user avatar
  • 111
1 vote
2 answers
385 views

Issue with backstack and bottomnav in kotlin

I have a bottom nav with 4 fragments Home, Following, Notification, and Profile, there is no issue with the bottom navigation on backstack , but now for eg from profile fragment I jumped to a fragment ...
Vasant Raval's user avatar
1 vote
3 answers
1k views

Navigate up from activity to fragment open the same fragment - Android Navigation Component

on this app, When I trying to navigate from "HomeFragment" to "DetailsActivity"then pressed back it's back to the same fragment and also the hamburger icon on click doesn't work ...
Dr Mido's user avatar
  • 2,474
0 votes
1 answer
2k views

Is there an easy way to prevent fragments from going back by using the back button on android

I am trying to figure out an easy solution without overcomplicating things on preventing certain screens in the app from going back when they use the back button of the android device however, I am ...
KCYrgn's user avatar
  • 251
0 votes
1 answer
394 views

How to get fragments from backstack when using Android Navigation Component?

How can I access any of the fragments in backstack when using Android Navigation Component? Let's sat you navigate to Fragment A then to Fragment B and then to Fragment C using Navigation Component. ...
Harry's user avatar
  • 323
0 votes
1 answer
260 views

open a fragment in a different level of hierarchy with backstack in Android Navigation component

I am using Navigation Component in my project and : I need to open a fragment in a different level of hierarchy, so that the back stack is created properly too in my nav_graph.xml there is a ...
imansdn's user avatar
  • 1,018
1 vote
0 answers
318 views

Create Instagram like bottom navigation with separate backstack

I'm new to android development and need some guidance. I'm trying to implement functionality like Instagram Bottom Navigation. Let me describe what do I mean by the functionality. Desired ...
Haxxan Parhar Developer's user avatar
0 votes
1 answer
115 views

BackStack not navigating to the correct Fragment

Hello im trying to navigate between some fragments with addToBaackStack but having issues with it , Ok i will explain it in detail so there should be no confusuion 1 :- I have only one activity (main ...
Vasant Raval's user avatar
0 votes
0 answers
783 views

Android navigation popBackStack in action has different behavior from findNavController().popBackStack(R.id.f1, false)

I'm using Android navigation with safeArgs. I have fragment 1 F1 with TabLayout. I have fragment 2 F2 with the button which should navigate to fragment F1 and clear the back stack history. If I use on ...
Martin Kulle's user avatar
0 votes
1 answer
62 views

android-clearing backstack generates NullPointerException

I have 4 fragments in my app : A, B, C and D. first of all, one instance of fragment A is added to the activity, without adding to backstack. then the user can dynamically navigate to indefinite ...
Soheil's user avatar
  • 597
0 votes
1 answer
63 views

addToBackStack is not navigating back to the correct fragment

hello im trying to include a backstack to EditProfile Fragment that when back is pressed it goes back to Profile Fragment but it goes back to the Home Fragment if you want more refrence of the code ...
Vasant Raval's user avatar
1 vote
0 answers
595 views

How to handle the back stack of bottom navigation with navigation component

I want to perform a navigation just like instagram and youtube and i tried many ways how should it be implemented? by the way it should work with the Jetpack's Navigation Component what is the newest ...
radman hayati's user avatar
0 votes
2 answers
113 views

What is the best way to manage BackStack in Fragment [duplicate]

Hello i want to manage BackStack in fragment i have implemented a method but im not happy with it becuase if i switch to multiple fragments again and again ,then i want that backstack dont switch to ...
Vasant Raval's user avatar
0 votes
1 answer
411 views

Android - pop Back Stack with toolbar button in a single activity app

I have a single activity application (Java). If the user is not logged in the first thing he sees is a welcome screen where he can sign in and then move to the home fragment. If the user is signed in, ...
cesarcarlos's user avatar
  • 1,303
0 votes
1 answer
491 views

How can I use the transaction backstack to pop fragments?

Suppose I have a MainActivity with FragmentContainerView. This FragmentContainerView's size matches the MainActivity. Then I want to show one fragment at a time in this FragmentContainerView. ...
jungrylls's user avatar
1 vote
0 answers
39 views

Can I add a fragment dynamically to the backstack without the xml?

I have a 2 fragments, one is my main fragment that I initialize in the main activity, and the other is one that I want to instantiate when a button is clicked on the first fragment. I am having issues ...
1QuickQuestion's user avatar
0 votes
0 answers
193 views

Android. Determine the first fragment in the activity

Is it possible to determine with which fragment the activity was started. For example, I have an activity, and several fragments, I need to return from the last fragment to the first, is it possible ...
testivanivan's user avatar
  • 1,114
0 votes
1 answer
839 views

Navigation PopUpToInclusive doenst work? When the app is reopened, it opens the Login Fragment instead of Email Login Fragment

I'm using android jetpack navigation and the flow of the app is: Login screen → Email Login screen nav_main.xml <fragment android:id="@+id/loginFragment" android:name="com....
Thiago Souza's user avatar
  • 1,341
6 votes
0 answers
641 views

Fragment Backstack after Process Death

As I observed it seems that the fragment backstack is not retained after process death. So if I kill my app by putting it to background and call am kill <app> it does not recreate the fragment ...
tscheppe's user avatar
  • 608
0 votes
0 answers
295 views

Why is replace() method saving the state of the Fragment?

I have a BottomNavigationView to navigate between 4 Fragments, the first one has a RecyclerView. When I select an item of the BottomNavigationView I use the replace() method to switch between the ...
Mário Fernandes's user avatar
0 votes
1 answer
38 views

Popbackstack always returns previous call

I've got three Simple Fragments: FragmentA, FragmentB, FragmentC. FragmentA -> FragmentB: FragmentB fragment2 = new FragmentB (); FragmentManager fragmentManager = getActivity()....
Funny Moments's user avatar
0 votes
2 answers
698 views

Pressing back button once stay on the same fragment, and if pressing twice, it will go back to previous fragment

I have following code package com.example.covid19 import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.fragment.app.add import ...
Teddy Consultant's user avatar

1
2 3 4 5
8