Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
How to navigate to existing Fragment from BackStack?

I have a bunch of fragments using a single activity as host.

My fragments are arranged like this,

Frag1 -> (Press Next) -> Frag2 -> (Press Next) -> Frag3 -> (Press Next) -> Frag4

In Frag1, I have a another button which will directly navigate to Frag4.

In Frag4, If I click back button it is currently going back to Frag1. But Here I want this to navigate to Frag3.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If I got what you want correctly, You can use popUpTo in Pop Behavior in the right side of your host xml where you connect fragments and navigate fragments and set popUpTo to a fragment that you want

or

you can use this code to say where to go when back button pressed:

Note: you need to paste them in fragment class

requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner) {
            add your navigation destonation or do whatever you want 
        }

you have another option too.

You can use:

view?.findNavController().popBackStack()

And last but not the least If you are in activty class I mean not Fragment you can use this:

override fun onBackPressed() {
do what you need
if you leave this fun empty, back button would not work any more        
}

I think second option is your fit

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!