The answer here using onBackPressed() is deprecated.
How to show a dialog to confirm that the user wishes to exit an Android Activity?
What's the new approach? Also, My activity contains fragments and I am using Navigation Component, onBackPressed() also triggered when I am inside fragment, need to avoid it.