4

Suppose I have added three fragments : A, B and C in a transaction and I commit the same. After commiting, onResume() methods for A, B and C are called successively.

Then, further I use replace function to replace it with a new instance of second fragment.

What I observed is: FragmentA is destroyed FragmentC is destroyed FragmentB is calling onStop() and not onDestroy()

A new instance of FragmentB is created and its onCreate() method is called.

My question is why is onDestroy() for FragmentB is not called?

Damian Kozlak
  • 6,917
  • 10
  • 44
  • 51
Ayush
  • 111
  • 1
  • 12

1 Answers1

0

onDestroy is not guaranteed to be called. This is true for both Activity and Fragment.

Take a look at here for more information:

fragment lifecycle: when "ondestroy" and "ondestroyview" are not called?

Why implement onDestroy() if it is not guaranteed to be called?

Community
  • 1
  • 1
tasomaniac
  • 9,884
  • 6
  • 49
  • 82