Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

285
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda