我用抽屉式导航实现了底部导航,并通过以下代码管理导航。在这种情况下,每次导航选择更改时都会加载新的片段实例。如何避免它并使用片段的旧实例。
drawer = findViewById(R.id.drawer);
navigationView = findViewById(R.id.navigationView);
bottomNavigationView = findViewById(R.id.bottomNavigation);
navController = Navigation.findNavController(this, R.id.main);
appBarConfiguration = new AppBarConfiguration.Builder(new int[]{ R.id.id1, R.id.id2, R.id.id3})
.setDrawerLayout(drawer)
.build();
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
NavigationUI.setupWithNavController(bottomNavigationView, navController);