0

I am using 4 fragments in 1 activity. The navigation is done via NavDrawer. Every time I navigate through the fragments, each fragment goes through the following methods: onAttach() to onDestroyView() I was expecting them to go through these once and then go through onCreateView() to onDestroyView() but this is not happening. I would like to initialize certain things only once in onCreate() but now I cannot. Does anybody have any experience with this?

  • Hi @Anthony, it really depends on your implementation. Maybe you "kill" the latest active fragment whenever you navigate from it. It's hard to tell without seeing your code. – Barak Apr 04 '19 at 15:03

1 Answers1

0

Hi Thanks for the reply. I found the problem. I was creating a new fragment in the nav drawers itemselect. To solve it I created an instance of each fragment in main activity and just set this to current fragment instead of creating a new one.

Thanks again

  • You will run into the same problems as this guy: https://stackoverflow.com/questions/55753099/app-crash-after-activity-has-been-killed-in-background/55754360#55754360 – EpicPandaForce Apr 25 '19 at 08:37