Customise Back and Navigation Up action
When you press the “Back” button, the screen of the app goes to the previous page(fragment or activity). However, if you want to have a custom behaviour (For example, pop up a dialog to ask the user to confirm again to exit when you are uploading something.) when you press the button. You can look at the steps below. You can also implement custom behaviour for the “navigation up” button of the Navigation component on the action bar.