MVVMCross 6.4.3 Restore is not working as expected

84 Views Asked by At

I have a view (A) from which I can navigate to another view (B)

If I tombstone the app when I am viewing view B

When I restore it I see the following getting called

  • View B - Constructor
  • View B - Reload from Bundle
  • View B - Prepare
  • View B - Initialize

Only when I close View B do I see the following

  • View A - Constructor
  • View A - Reload from Bundle
  • View A - Prepare
  • View A - Initialize

I would have expected when restoring to see the lifecycle events for View A followed by the lifecycle events for View B. This is because I thought the complete hierarchy is constructed before restore is complete.

Am I wrong, or am I missing something here?

Can someone confirm the expected behaviour.

1

There are 1 best solutions below

0
On

No, when you are on View B and then close View B, you do not see all these functions called:

  • View A - Constructor
  • View A - Reload from Bundle
  • View A - Prepare
  • View A - Initialize

You need to understand why each one is called. The constructor is called ONLY when a new instance of that ViewModel is created. Closing B doesn't create a new instance. You would have to close View A while ensuring everything is disposed and then reopen it.

Similarly, the other lifecycle functions also have a purpose. You might want to use the Did Appear overrides.

To verify this, you can also just create a simple sample and add logging.