Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android -does calling finish from activity destroy hosted fragment?

I have an 'Activity A' which host a 'Fragment B'. Please confirm that if I call A.finish() then 'fragment B 'gets destroyed. The fragment B would already be added to the fragment manager. I realize that a fragment is a sub-activity but i want to know do i have to tell the fragment manager to release the fragment in Ondestroy or is it all taken care of ?

like image 328
j2emanue Avatar asked Aug 20 '14 20:08

j2emanue


1 Answers

but i want to know do i have to tell the fragment manager to 
release the fragment in Ondestroy or is it all taken care of ?

By default when you call finish in your activity it will automatically call onDestroy method of all the fragments that is attach to the activity thus destroying it, so no need to worry about destroying the fragment in onDestroy method of your activity.

From the documentation:

For example, when the activity is paused, so are all fragments in it, 
and when the activity is destroyed, so are all fragments. 
like image 199
Rod_Algonquin Avatar answered Oct 05 '22 10:10

Rod_Algonquin