Stylianos Gakis
03/02/2023, 3:00 PMnavController::popBackStack
, but if the backstack is empty, then simply have it call onBackPressedDispatcher.onBackPressed()
. Am I missing some sort of API that already exists?
What is not working for me is that I launch an activity which has its own NavHost. When I am on the “top level” route of that activity, I have a TopAppBar which has the back button. When that back button is pressed, if we are at that empty backstack state, I want it to simply let the back press go to onBackPressedDispatcher
so that it actually finishes the current activity.
Now when I do navController::popBackStack
it simply does nothing (and returns false as the result of popBackStack)Ian Lake
03/02/2023, 3:22 PMIan Lake
03/02/2023, 3:29 PMnavController.navigateUp() || onSupportNavigateUp()
(if you are using AppCompatActivity, onNavigateUp otherwise)Stylianos Gakis
03/02/2023, 9:21 PMnavController.navigateUp() || onSupportNavigateUp()
should be specifically done for when one clicks on the top app bar, to follow the instructions from the docs here.
Thanks a lot Ian 🤗Stylianos Gakis
03/03/2023, 8:29 AMnavController.navigateUp() || onSupportNavigateUp() || finish()
inside my activity, since that was returning false and not exiting either, but I did in fact want it to finish my activity with the way everything is setup now.
In a future where we won’t have all these activities I guess I can remove such stuff, but for now it is what it is,Ian Lake
03/03/2023, 3:43 PMparentActivityName
in your manifest, which is a requirement for the system to know what onSupportNavigateUp
is supposed to do: https://stackoverflow.com/questions/19207762/must-i-specify-the-parent-activity-name-in-the-android-manifestStylianos Gakis
03/03/2023, 3:52 PM<activity> ...
block in the :app module too instead of having it isolated in the child module so that it can reference itStylianos Gakis
03/03/2023, 4:00 PMStylianos Gakis
03/03/2023, 4:17 PMStylianos Gakis
03/03/2023, 4:48 PMIan Lake
03/03/2023, 6:42 PMStylianos Gakis
03/03/2023, 6:52 PMIan Lake
03/03/2023, 7:23 PMStylianos Gakis
03/03/2023, 7:56 PM