Когда я меняю вкладку BottomNavigation, фрагмент будет воссоздан.
Как кэшировать созданный фрагмент, а не воссоздавать заново?
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
bottomNavigationView = view.findViewById(R.id.bottom_navigation);
NavController navController = Navigation.findNavController(getActivity(), R.id.bottom_nav_host_fragment);
NavigationUI.setupWithNavController(bottomNavigationView, navController);
this.initBottomNavigation();
}
private void initBottomNavigation() {
bottomNavigationView.setOnNavigationItemSelectedListener(item -> {
NavController navController = Navigation.findNavController(getActivity(), R.id.bottom_nav_host_fragment);
return NavigationUI.onNavDestinationSelected(item, navController)
|| super.onOptionsItemSelected(item);
}