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
  • 7,065
  • 10
  • 45
  • 51
Ayush
  • 121
  • 2
  • 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
  • 10,234
  • 6
  • 52
  • 84