0

I want to avoid reloading of fragments when I switched the tabs of a BottomNavigationView. I really don't know how to do it. The reason is when I switch between tab 1 and 2, the phone lags too much.

BottomNavigationView navView = findViewById(R.id.nav_view);

AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
        R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
        .build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(navView, navController);

Thanks for your help.

Son Truong
  • 13,661
  • 5
  • 32
  • 58
Ahmet Aziz Beşli
  • 1,280
  • 3
  • 19
  • 38
  • My opinion is that it's not a good idea to leave the fragments loaded in the back. That would create even more lag. Have you tried your application in a real phone? If you haven't, try that. If you tried that and it lags on a real phone, I would guess you're doing too many things on that fragment. Or maybe it's an animation you're implementing that's glitching? You could provide a video as well of what this lag looks like. – Lheonair Nov 30 '20 at 22:04
  • 1
    https://stackoverflow.com/questions/42362917/fragment-re-created-on-bottom-navigation-view-item-selected – private static Nov 30 '20 at 22:05
  • @Lheonair In the first tab I am opening the camera of the phone and I am switching between the tabs. That's why it lags because of the camera operation. – Ahmet Aziz Beşli Nov 30 '20 at 22:11

0 Answers0