You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is actually a major issue in the current examples.
Using backstack.goBack() before super.onBackPressed() means that the dispatcher won't receive it before the backstack going back.
/** * Called when the activity has detected the user's press of the back * key. The {@link #getOnBackPressedDispatcher() OnBackPressedDispatcher} will be given a * chance to handle the back button before the default behavior of * {@link android.app.Activity#onBackPressed()} is invoked. * * @see #getOnBackPressedDispatcher() */@Override@MainThreadpublicvoidonBackPressed() {
mOnBackPressedDispatcher.onBackPressed();
}
Basically, Jetpack team should have probably made onBackPressed final with this new current approach, as the order cannot be correct if you do anything before calling super.onBackPressed.
The solution is to register an always-enabled callback, but the Activity actually tries to close the action bar first instead of finishing.
onBackPressedDispatcher.addCallback(this, object:OnBackPressedCallback(true) { // always intercept.overridefunhandleOnBackPressed() {
val topKey = backstack.top<FragmentKey>()
val fragment = supportFragmentManager.findFragmentByTag(topKey.fragmentTag)
if (fragment isBackHandler) {
val handled = fragment.handleBack()
if (handled) {
return
}
}
if (!Navigator.onBackPressed(this@MainActivity)) {
finish() // we cannot access Activity.onBackPressed() anymore. RIP
}
}
})
I don't see a way to access Activity.onBackPressed() because super.onBackPressed() would just send to the dispatcher again, causing an infinite loop.
What the heck.
The text was updated successfully, but these errors were encountered:
This is actually a major issue in the current examples.
Using
backstack.goBack()
beforesuper.onBackPressed()
means that the dispatcher won't receive it before the backstack going back.Basically, Jetpack team should have probably made
onBackPressed
final with this new current approach, as the order cannot be correct if you do anything before callingsuper.onBackPressed
.The solution is to register an always-enabled callback, but the Activity actually tries to close the action bar first instead of finishing.
I don't see a way to access
Activity.onBackPressed()
becausesuper.onBackPressed()
would just send to the dispatcher again, causing an infinite loop.What the heck.
The text was updated successfully, but these errors were encountered: