Book Image

Cross-platform UI Development with Xamarin.Forms

By : Paul Johnson
Book Image

Cross-platform UI Development with Xamarin.Forms

By: Paul Johnson

Overview of this book

Table of Contents (22 chapters)
Cross-platform UI Development with Xamarin.Forms
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
In the Beginning…
Index

Instantiating Xamarin Forms within an app


We instantiate Xamarin Forms within each supported platform of the app. Xamarin Forms support the following platforms:

  • Android

  • iOS

  • Windows Phone

Android

Typically, an activity to start an activity class looks like this:

public class MyActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
         base.OnCreate(bundle);
         // then whatever you need to do

To start a Xamarin Forms app, this changes as we are not inheriting the Activity but a FormsApplicationActivity, or more precisely:

public class MyActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
    protected override void OnCreate(Bundle bundle)
    {
         base.OnCreate(bundle);
         global::Xamarin.Forms.Forms.Init(this, bundle);
         LoadApplication(new App());
    }
}

iOS

As with Android, we inherit FormsApplicationDelegate in AppDelegate instead of the usual UIApplicationDelegate:

[Register("AppDelegate")]
public partial class AppDelegate...