Start an Activity

PDF for offline use
Related Articles:
Related SDKs:

Let us know how you feel about this

Translation Quality


0/250

This recipe shows how to start an activity defined within an application.

Recipe

To start an Activity, follow these steps.

  1. Create a new Xamarin.Android application. The project template will create a single activity named MainActivity (MainActivity.cs), which contains a button.
  2. Add a second activity class named Activity2 to the project. This class must inherit from Android.App.Activity
  3. From the button.Click handler in MainActivity.cs, call StartActivity , passing the type of the activity to start, Activity2 in this case.
button.Click += delegate {
       StartActivity(typeof(Activity2));
};

Additional Information

Each screen in an application is represented by an activity. For more information on activities see the Getting Started series and the Activity Lifecycle in the Xamarin.Android documentation.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.