Monday, 24 August 2020

How to add logging to navigation back or up using navigation architecture component?

I am using the navigation component in my Android app, which automatically provides me with back and up navigation. Now I don't want to change any of those behaviours, but I want to add some logging specific to the fragment where the user presses either the up button in the toolbar or the back button.

I tried this, and it worked only for the back button, and I didn't figure out how to leave the default navigation behaviour intact. Plus it seems like this adds a callback at the activity level, so it's not specific to the fragment where I add the callback.

And it seems like onOptionsItemSelected is called for normal menu items, but not for the Up button.

How can I handle this consistently without changing the behaviour of my entire app?



from How to add logging to navigation back or up using navigation architecture component?

No comments:

Post a Comment