简体   繁体   中英

ListFragment is empty after navigating back

Okay, I know there is a lot of discussion according to this topic, but I couldn't find any answer.

My problem is the following: I have an Activity with NavigationDrawer , so the Fragments are added from code. The first fragment is a ListFragment , witch reads data from an SQLite DB stored in the SD card. The data loading is kind of slow, because I load the nearest n place based on location. So I don't want to load the list every time.

Now, if the user clicks an item, a second Activity shows the details. The first strange stuff is the first activity is destroyed almost every time a leave it, witch is awful, but still I could save the state.

The discussions that I rad so far indicated that the Activity should retain the last displayed Activity , and it kind of does, because if I change the content of the first activity from the Drawer before navigation the correct Fragment is created.

The problem is that even if the ListFragment is being re-used its contents will be missing (since I create a new View in the onCreateView() because of custom layout). I guess I should use the Bundle provided as a parameter in onCreateView() , but I just couldn't figure it out.

So summed up: what is the proper way of saving the items of a ListFragment , even if its parent activity is destroyed?

It turned out that I had a developer option turned on that killed all Activities that I navigate from. I didn't know that because I use my phone in Hungarian (guess it'll change from now), and for some reason they felt like they had to translate the word "Activity", making the whole option description not understandable. Sorry about that, now my first Activity is kept in the memory, so the whole issue is not present...

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