0
In my action I use the method onBackPressed
. When will I compare the fragment
that triggered the event the Id
is never the same and always falls in the else
. what is wrong?
override fun onBackPressed() {
val fragment = this.supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val pressed = fragment?.childFragmentManager.fragments?.get(0) as IOnBackPressed
var currentFragment = fragment?.childFragmentManager.fragments?.get(0)
pressed?.onBackPressed()?.takeIf { it }?.let {
when(currentFragment.id) {
R.id.embalagemItemFragment -> {
// implemetation
}
else -> {
super.onBackPressed()
}
}
}
}