0

I try to log all of fragment life-cycle inside viewpager which using StateFragmentAdapter.Fragment A move to fragment C and it logged that fragment A is onDestroy and onDestroyView.but when i return to fragment A,the memory addresss of that fragment same as the destroyed fragment.So i wonder that is that it create a new fragment on the same addresss or it's still that fragment inside that addresss?

shadow
  • 114
  • 11
  • can you post your code ? – akshay_shahane Aug 28 '19 at 10:41
  • @akshay_shahane i will update my question – shadow Aug 28 '19 at 10:41
  • how exactly are you getting the memory address btw? – Kushan Aug 28 '19 at 10:42
  • @Kushan i just print the fragment.so just like other object it print the memory address right? – shadow Aug 28 '19 at 10:43
  • 1
    no, that it not the memory address, java does not allow access to memory address. It is default toString() output and is pretty much useless for anyone. Your fragment will always get re created from scratch after a call to onDestroy – Kushan Aug 28 '19 at 10:46
  • 2
    what you are seeing is classname@hexstring_of_hashcode_of_object – Kushan Aug 28 '19 at 10:48
  • @Kushan but why the result of fragment.toString() is always the same String even when the fragment is destroyed and another fragment is created? – shadow Aug 28 '19 at 10:51
  • 2
    If two Objects are equal, according to the the equals(Object) method, then hashCode() method must produce the same Integer on each of the two Objects. each fragment which is recreated is basically the exact same object so you get the exact same value of hashcode and thus you get the exact same output. – Kushan Aug 28 '19 at 10:55
  • @Kushan thank you for all of this knowledge!!! upvoted all!!! – shadow Aug 28 '19 at 10:56

0 Answers0