So, I have Fragment with WebView in it and the user is expected to navigate in it, browse some whole site, maybe add something to cart and hopefully proceed to checkout. What happens when the user taps on the back button on Android’s navigation bar? Yes, the fragment is destroyed and the user is navigated back. But that’s no good. Let’s fix that.
I’m honestly sad, but yes, this is interface that will be implemented by activity
We will use this back pressed callback in fragment. This is where magic happens
Actual implementation in Activity
This can be also useful when a fragment has selection mode (e.g. selecting items from recycler view) and the user can tap on the back button to return to normal viewing mode