5

As the title says I am using Navigation Components to navigate from fragment to another inside the same navGraph, each time I navigate, the onDestroyView method is called and the whole view gets destroyed, I am sure you know that formerly.

Two questions here,

  1. am I missing something?
  2. If I have a huge complex view like a RecyclerView in one of the fragments for example, what should I do to prevent it from being destroyed(and destroying the user experience with it) and being recreated again.

Thanks

Mohammad Elsayed
  • 1,885
  • 1
  • 20
  • 46
  • Check this one https://stackoverflow.com/a/55039009/6618058 – mehmet salim ayan Dec 15 '20 at 11:50
  • If you cache the expensive data in the viewmodel attached to the activity, it's not hard for the RecyclerView to re-create the N-visible viewholders – MatPag Dec 15 '20 at 11:55
  • data is cached, and not destroyed, no time at all is consumed in fetching the data since it's ready BUT showing this data in the UI (RecyclerView in my case) takes like .2 to .5 seconds which is verrrry annoying and eye displeasing @MatPag – Mohammad Elsayed Dec 15 '20 at 12:00
  • You should optimize your viewholder binding code. You can use the Profiler tool (`View -> Tool windows -> Profiler`) to see where is the bottleneck and try to solve the problem – MatPag Dec 15 '20 at 13:02
  • the behavior has changed in the latest release. See: https://stackoverflow.com/a/69308302/6139861 – rafsanahmad007 Sep 24 '21 at 00:47

0 Answers0