Xamarin.Forms Projects
上QQ阅读APP看书,第一时间看更新

Adding a bootstrapper in Android

Just like for iOS, the Bootstrapper for Android is a simple wrapper for the common bootstrapper defined in the .NET Standard library, but with the addition of an Init method that will be called at startup:

  1.  In the root of the Android project, create a new class called Bootstrapper.cs.
  2. Add the following code to it:
public class Bootstrapper : DoToo.Bootstrapper
{
public static void Init()
{
var instance = new Bootstrapper();
}
}

We then need to call this Init method. A good place to do this is right before the LoadApplication call in OnCreate:

  1. Open up MainActivity.cs.
  2. Locate the OnCreate method and add the code in bold:
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;

base.OnCreate(bundle);

global::Xamarin.Forms.Forms.Init(this, bundle);
Bootstrapper.Init();
LoadApplication(new App());
}