Search code examples
xamarinmvvmcrosslifecycle

MvvmCross V5 ViewModel Lifecycle


I am looking at upgrading from version 4 to version 5 of MvvmCross and I have a couple of questions on the the ViewModel lifecycle.

I am familiar with the V4 lifecycle, (Construct, Init, ReloadState and Start) but am not sure how they map to V5

My questions are:

  1. I understand Prepare and Initialize, but which of those is the equivalent of Start()?

  2. Are the SaveState and ReloadState methods still available in the V5 ViewModel lifecycle? Will it just work as it did before? If not, how do I manage this?


Solution

  • In older versions of MvvmCross we had Init for setting variables and Start for doing heavier (possibly async) work. Start was a void method that could be turned into async void, which was not nice at all.

    Newer version now have Prepare for dealing with passed parameters in a statically typed fashion and Initialize for running asynchronous code and, as the name implies, initialize your ViewModel. Those are, IMO, much better named and objectively better to work with than the previous approach.

    Regarding your second question, SaveState and ReloadState still work fine even if using the new navigation service.

    For further doubts you can read the migration guide and the ViewModel lifecycle docs