0

I used to think that all of global variable is destroy it self when fragment is destroy (in onDestroy) or maybe sometime it will removed by Garbage Collector.But when trying to check the variable instance in onDestroy,it not be clean up by fragment.As i remember onDestroy is called to do final cleanup of the fragment's state (follow to this https://developer.android.com/reference/android/app/Fragment.html#onDestroy()) so why the variable is still not been removed? ( i also checked inside onDetach but the result is still the same)

  • 1
    `onDestroy` simply means the fragment is about to be destroyed... not already destroyed. – Giddy Naya Aug 12 '19 at 04:07
  • thanks for reply @GiddyNaya ,but reference to that link,the state will be destroy it state.so if not,when will all the variable be destroy – Nghiem Ba Cuong Aug 12 '19 at 04:11
  • 1
    `onDetach()` is the method you're looking for. Read more https://developer.android.com/reference/android/app/Fragment.html#onDetach() – Rahul Khurana Aug 12 '19 at 04:14
  • @RahulKhurana oh,sorry i will add more in my question.i was try to check the variable after super.onDetach().it still not be clean ( i try to delay the check for 2-3 second). – Nghiem Ba Cuong Aug 12 '19 at 04:20
  • @Nghiem Ba Cuong Yes the app state will be destroyed `but only after it has been executed.` Any block you specify under `onDestroy` will be executed just before the fragment is destroyed that is what it implies until then your variables still exist. – Giddy Naya Aug 12 '19 at 04:20
  • @GiddyNaya great answer.so is there anyway can i check that all of the variable is remove or any callback?? – Nghiem Ba Cuong Aug 12 '19 at 04:23
  • 1
    @NghiemBaCuong What do you want to do with those variables? – Rahul Khurana Aug 12 '19 at 04:23
  • @NghiemBaCuong Have you define your variable as a static variable? – Ashish Kakadiya Aug 12 '19 at 04:25
  • Nice reply @Rahul Khurana. it would be helpful to share your reason for tracking the existence of the variables to determine the right answer to give you. – Giddy Naya Aug 12 '19 at 04:29
  • @GiddyNaya oh, i'm new Android Developer and i just really want control,handle the lifecycle and all about it for after development.^^.so any knowledge of this u guys can help me to know it.many thanks to u all supported – Nghiem Ba Cuong Aug 12 '19 at 04:35
  • @AshishKakadiya no,it just a normal variable – Nghiem Ba Cuong Aug 12 '19 at 04:38
  • @RahulKhurana i answer your question above 2 comment but SOF not allow tag 2 people.sr bout that – Nghiem Ba Cuong Aug 12 '19 at 04:39
  • @NghiemBaCuong You can also destroy your variable onDestroy() method – Ashish Kakadiya Aug 12 '19 at 04:42
  • 1
    @NghiemBaCuong don't worry about these types of customization in the begining phase just learn about the lifecycle steps, passing arguments, both Implicit and Explicit Intent – Rahul Khurana Aug 12 '19 at 04:43

0 Answers0