简体   繁体   中英

how to store the state of fragment with navigation bottom menu

I'm trying to store the value of my fragments components inside an activity with lower navigation menu, controlled by navController. My problem is that when I change one fragment to another (onPause) with the bottom navigation, or rotate the screen, all my data in the component layout is lost. is there a solution to solve this problem?

Store the data in a Viewmodel and observe it from the UI. The stored data is not lost if the framework destroys and re-creates the activities and fragments during a configuration change or other events.

https://developer.android.com/topic/libraries/architecture/viewmodel?hl=en

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM