My current Android project has the following code
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
super.onBackPressed()
return true
}
else -> false
}
}
e.g. when the toolbar home icon is clicked I call onBackPressed()
and the user navigates to the previous location within the app.
onBackPressed()
is now deprecated and I am informed I need to employ getOnBackPressedDispatcher()
, I do not see how this dispatcher can replace my call to onBackPressed()
.
what am I missing?
how should I refactor my code now that onBackPressed()
is deprecated?