Starting app components

All apps have several components that make up the app. These can be screens, chunks of work, and listeners that wait for an event to happen somewhere.

How to do it...

There are three basic components to any app: the Activity, the Service, and the BroadcastReceiver component:

  1. The most common and most visible component is the Activity component:
    [Activity]
    public class DestinationActivity : Activity {
      protected override void OnCreate(Bundle savedState) {
        base.OnCreate(savedState);
      }
    }
  2. To start or display an activity, we simply invoke the StartActivity() method, as follows:
    var intent = new Intent(this, typeof(DestinationActivity));
    StartActivity(intent);
  3. The next component that we use is a Service, or the chunk of work:
    [Service] ...

Get Xamarin Mobile Development for Android Cookbook 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.