0

Have implemented the new navigation architecture component on my app and i wonder how i can implement saving the state i have a five fragments when i navigate from one fragment to another the instance is restarted again and again wherever i navigate now i want to save the instance that when i come back to certain fragment i find the same instance as i left it if the button pressed they should stay the same.

Here is may activity having the five fragmenst

```
public class MainActivityCenterofInformation extends AppCompatActivity {


    BottomNavigationView bottomNavigationView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContentView (R.layout.activity_maincict);

        setUpNavigation ();





    }

    public  void setUpNavigation(){
        bottomNavigationView = findViewById (R.id.bottom_nav_cict);
        NavHostFragment navHostFragment = (NavHostFragment)getSupportFragmentManager ()
                .findFragmentById (R.id.nav_host_fragment_cict);
        NavigationUI.setupWithNavController (bottomNavigationView, navHostFragment.getNavController ());
    }

}```

Have tried several ways like saving Ui state but it doesn't work also i need it in java not kotlin guys i cant read kotlin

Kyle Mutta
  • 379
  • 1
  • 5
  • 16
  • Does this answer your question? [Android navigation component: how save fragment state](https://stackoverflow.com/questions/56195791/android-navigation-component-how-save-fragment-state) – Bö macht Blau Dec 06 '19 at 18:36
  • tried but not helpful bro – Kyle Mutta Dec 06 '19 at 18:38
  • You can use this disgusting hack from the Navigation AAC authors https://github.com/android/architecture-components-samples/blob/1f4840cfb8b1c1820d375ee208a18bd743ab5326/NavigationAdvancedSample/app/src/main/java/com/example/android/navigationadvancedsample/NavigationExtensions.kt#L35-L250 or just remove Navigation component from your project – EpicPandaForce Dec 07 '19 at 08:04
  • thanks @EpicPandaForce but its in kotlin i need the java one – Kyle Mutta Dec 07 '19 at 17:36
  • It's the same in both languages, just different syntax. – EpicPandaForce Dec 07 '19 at 18:10

0 Answers0