Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
button back in startDestination with navigation component

I need a second activity with a nav graph and have a return button in toolbar to the first activity that also contains a nav graph

In my second activity I have onSupportNavigateUp and setupActionBarWithNavController when entering the fragments if the arrow back button appears but in the activity no.

Try adding setHomeButtonEnabled and setDisplayHomeAsUpEnabled in both the activity and the fragment and if the button appears back, but when I enter some fragment in front and return to the fragment startDestination disappears the button back

I just need to keep the button back in the activity and solve my problem

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

You can do it by specifying a setFallbackOnNavigateUpListener:

private fun setupToolbar() {
    val navController = findNavController(R.id.nav_host_fragment)

    val appBarConfiguration =
        AppBarConfiguration.Builder()
            .setFallbackOnNavigateUpListener { onNavigateUp() }
            .build()

    dataBinding.toolbar.apply {
        setupWithNavController(navController, appBarConfiguration)
    }
}

And then do whatever you want in the Activity's:

override fun onNavigateUp(): Boolean {
    finish()
    return true
}
over 4 years ago · Santiago Trujillo Denunciar

0

You can't, activity has their own toolbars and in your case they have two different NavControllers. So your second activity manage NavUp Button for his fragment and when start Destination fragment comes NavUpButton(Backbutton) disappear because it has no destination left behind. And if you programmatically show NavUp Button on start destination of that (2nd activity) and manage onClick and start first activity that always goes to Start destination of first activity's fragment because it has it's own Nav Controller.

Problem is that Navigation UI not works like that. The better approach is use only one activity with multiple fragments. And use any other approach to solve your problem within the same nav controller.

over 4 years ago · Santiago Trujillo Denunciar

0

Add setHomeButtonEnabled func. to your returning action. If you are returning with button add it to onClick or with backPress, override backPress.

With this solve : You will set your button enable, when you try to return your startDestination.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda