Search code examples
c#xamarin.formsmvvmcross

do we have to initialize Xamarin.Forms in MvvmCross in Android?


I am having a simple sample in MvvmCross. In that, I have installed Xamarin.Forms version 3.4 and MvvmCross version 6.6.

My doubt is:

  1. What is the purpose of initializing this code global::Xamarin.Forms.Forms.Init(this, bundle) in android Renderer ?
  2. Do we have to initialize Xamarin.Forms in MvvmCross version 6.6 in android renderer?

Solution

  • What is the purpose of initializing this code global::Xamarin.Forms.Forms.Init(this, bundle) in android renderer?

    If you check the Xamarin.Forms official quote on this it goes something like this:

    The OnCreate override initializes the Xamarin.Forms framework by calling the Init method. This causes the Android-specific implementation of Xamarin.Forms to be loaded in the application before the Xamarin.Forms application is loaded. In addition, the MainActivity class stores a reference to itself in the Instance property. The Instance property is known as the local context and is referenced from the PhoneDialer class.

    The quote is self-explanatory but just to help you a little bit it is basically used to load the Android specific implementation that Xamarin.Forms Framework needs at Runtime.

    do we have to initialize Xamarin.Forms in MvvmCross version 6.6 in android renderer?

    No, you do not need to initialize this in MvvmCross, as MvvmCross does it for you in the background. For more information on how to setup MvvmCross for Xamarin.Forms check this