Closed kaka1998 closed 6 years ago
Hi @kaka1998,
Yes that was the intended behaviour in the original release. You'll have to make sure that back button doesn't invoke pop when you're already on the root. If you're using the sample app for instance you should change
override fun onBackPressed() {
if (fragNavController?.popFragment()?.not() == true) {
super.onBackPressed()
}
}
to
override fun onBackPressed() {
when {
fragNavController?.isRootFragment?.not() == true -> fragNavController?.popFragment()
else -> super.onBackPressed()
}
}
Hi @mateherber
Thank you I'm using java and my onBackPressed now it's:
@Override public void onBackPressed() { if (!mNavController.isRootFragment()) { mNavController.popFragment(); } else { super.onBackPressed(); } }
bot when navigate between bottom navigation and press back close all app and exit app and not back to pre fragment. I need work like a demo and back to fragment and child fragment on bottom navigation
@kaka1998 To be able to pop from the stack first you'll have to push to it using fragnaccontroller.pushfragment()
@mateherber Thank you In sample fragNav use pushfragmen on click button by id button and don't use on click button navigation buttons but it's work nice. What it's working without use pushfragmen ? I have not any button in my app and only use button navigation and fragments.
Hi When use Builder cannot use FragNavTabHistoryController.UNLIMITED_TAB_HISTORY in switchController and without use FragNavTabHistoryController.UNLIMITED_TAB_HISTORY when click back button get this error: java.lang.UnsupportedOperationException: You can not popFragment the rootFragment. If you need to change this fragment, use replaceFragment(fragment) My code this is
mNavController = FragNavController.newBuilder(savedInstanceState, getSupportFragmentManager(), R.id.frame_fragmentMain_container ) .transactionListener(this) .rootFragmentListener(this, 5) .switchController(new FragNavSwitchController(){ @Override public void switchTab(int i, FragNavTransactionOptions fragNavTransactionOptions) { bottomNavigationBar.selectTab(i); } }) .build();