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

206
Views
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 answers
Answer question

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 Report

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 Report

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 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!