Access Back Icon (Android Navigation Component)

See that back icon

When using Android Navigation Component, Navigation host, the back button is automatically generate,…

But in my case, I can’t access it

So I type this code to my “Activity”

There are 2 overrided function there “onCreate()” and “onOptionItemSelected()”.

The onCreate() function job is to handle the navigation controller, and

The onOptionsItemSelected() function is to handle the clicked Option Item, but don’t forget to insert the “when” statement, so that it listen to back icon. I don’t know for sure, but android studio seems to give “” as back icon’s id.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store