Reputation: 4109
In my application, I have multiple activities and fragments. I know that when application is in background, system may destroy the activities. But, is it also possible that system destroys only a fragment and not its activity? My, understanding is that only complete activities are destroyed by the system but I am not able to find a concrete answer. Please help
Upvotes: 0
Views: 526
Reputation: 79
The fragment's lifecycle is directly affected by the host activity lifecycle, as stated here.
What that means is that the fragment will be destroyed/paused etc only when that happens to the host activity too. So the answer is no, the system will not kill your fragment if your activity is on the foreground.
Also consider this: a fragment is a component of your activity. A UI component is also part of an activity. If the system were to kill a fragment it would be like "killing" a Button on your UI.
Upvotes: 1