2

I am using the androidx.navigation to navigate around the fragments. I am seeing different behavior across different versions of FOS.
When i switch between the fragments onDestroy

public void onDestroy() {}

is not called for api 21 and 22 right away. It gets called only when i try to create the same fragment again.

For api > 24, same method is called right away.

Whats the different? why this behavior, I have to do some cleanup which i am doing in onDestroy. Should i use the onDestroyView instead ?

Pavan Tiwari
  • 3,077
  • 3
  • 31
  • 71

1 Answers1

2

Apparently, onDestroyView is recommended for that purpose:

onDestroyView() allows the fragment to clean up resources associated with its View.

Source: https://developer.android.com/reference/android/app/Fragment#Lifecycle

Mickey Tin
  • 3,408
  • 10
  • 42
  • 71