Configuring Xamarin.Essentials on Android

We need to initialize Xamarin.Essentials on Android by calling an initialization method. We do this by going through the following steps:

  1. In the Android project, open the MainActivity.cs file.
  2. Add the code in bold under the global::Xamarin.Forms.Forms.Init method:
protected override void OnCreate(Bundle savedInstanceState)
{
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;

    base.OnCreate(savedInstanceState);

    global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
    Xamarin.Essentials.Platform.Init(this, savedInstanceState);
    
    LoadApplication(new App());
}

That's it. We are all good to go.

Get Xamarin.Forms Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.