Question: I am using Android Jetpack Navigation to navigate between fragments in my App and using a single Main Activity. I have a nav host fragment in main activity and a bottom navigation to naviagte between fragments.

```
navController = Navigation.findNavController(this,R.id.nav_host_fragment_container);
BottomNavigationView bottomNavigationView = findViewById(R.id.bot_nav_bar);
NavigationUI.setupWithNavController(bottomNavigationView,navController);

```

But I have a major issue - whenever I navigate to another fragment, the current fragment is destroyed and when I navigate back, it is recreated, along with the view model. Then the view model again fetches the data from the repository. 

How can I fix this issue. I want to navigate between the tabs and load other fragments without destroying the current one.

Answer: 
You have to create your custom NavHostFragment(). There is a simple example here 

<https://medium.com/@programmerr47/navigate-back-with-navigation-component-6cec37ba6964>
You can do it 
1. Create object from your fragment exp:

```
final Fragment frag1 = new Fragment1();
final Fragment frag2 = new Fragment2();
final Fragment frag3 = new Fragment3();

```

After this u need to create object from FragmentManager like this 

```
final FragmentManager fm = getSupportFragmentManager();
Fragment active = frag1;

```

finally add fragment to fm like this 

```
fm.beginTransaction().add(R.id.main_container, frag3, 
"3").hide(frag3).commit();
fm.beginTransaction().add(R.id.main_container, frag2, 
"2").hide(frag2).commit();
fm.beginTransaction().add(R.id.main_container,frag1, "1").commit();

```

well work but don't forget to add "main\_container" in xml file 

main\_container 

```
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".view.activity.MainActivity"
tools:showIn="@layout/activity_main"
android:id="@+id/main_container">

</FrameLayout>

```

Now need to add in YourActivity 

```
<include
layout="@layout/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

```

now in actionListener 

```
fm.beginTransaction().hide(active).show(frag3).commit();
active = frag3;

```