0

I have a viewpager with 10+ pages in it, each page corresponds to its PageFragment and PageViewModel instances. When I start to swipe fragments one after another the onCleared() method is called for viewmodel that was left behind 2-3 steps ago, for example when I'm on page 7 the 4-th viewmodel is destroyed. The problem is, when I reach position 8-10 the onCleared() method starts to trigger also for this active viewmodel, which results to bad data representation on screen. Official documentation says that onCleared() is called whenever the viewmodel is not used anymore and should be destroyed, but how should it be destroyed if its data is represented on the active fragment

I tried to find any info about onCleared() method, but found almost nothing. Stack trace contains nothing suspicious. I presume that there is a force lifecycle methods call mechanism, but possible causes of its intervention in my case are unknown to me.

Please share your thoughts why is this behavior happening and how could I fix it.

FarVoyager
  • 49
  • 4

0 Answers0