Reviewing the generated elements

Prior to wrapping this chapter up, let's look at some of the things that go on behind the scenes.

Peer objects

In Chapter 3, Demystifying Xamarin.Android, we discussed the role of peer objects in a Xamarin.Android app. Let's now take a look at one of the generated Java peer objects from our project. The source for these classes can be found in NationalParks.Droid/obj/Debug/android/src. Open nationalparks.droid.MainActivity.java. Now, note the following pointers:

  • MainActivity extends android.app.Activity.
  • Each method we created an override for has a corresponding method created that calls our override. For example, we created an override for OnCreate(). The generated class has a method named onCreate() that calls a private native method n_onCreate(), which in turn points to our override through a JNI reference.
  • The static class initializer for MainActivity registers all the native methods for use with JNI using the mono.android.Runtime.register() method.
  • The class constructor activates an instance of our managed C# class using the mono.android.TypeManager.Activate()method.

The AndroidManifest.xml file

Xamarin.Android generates an AndroidManifest.xml file at build time using two sources as input: the first one being the content in the AndroidManifest.xml file in NationalParks.Droid/Properties and the second one being the attributes specified on classes, primarily activities in your project. You can find the generated AndroidManifest.xml in NationalParks.Droid/obj/Debug/android. Open the file with a text editor and note the following pointers:

  • There are two <activity/> elements in the file and MainActivity is specified to be the launch activity. These entries are generated from the attributes specified on each of the activity classes.
  • A single permission of INTERNET is specified. This came from the AndroidManifest.xml file in the NationalParks.Droid/Properties folder.

The APK file

Another interesting thing to look at is the APK produced for a Xamarin.Android app. We will be covering in detail how to create APKs in Chapter 10, Preparing Xamarin.Android Apps for Distribution. This a fairly simple process; if you can't wait, use the following steps:

  1. In the upper-left hand corner of the toolbar, set the built type to Release.
  2. From the Project menu, select Publish Android Project.
  3. In the Publish Android Application dialog box, choose Create new keystore, fill out all of the required information, and click on Create.
  4. Xamarin.Android will publish the APK in the location you selected. As APKs are ZIP files, simply unzip the APK to view the contents.

    The following screenshot shows the contents of the resulting APK:

    The APK file

The following table provides a description of the contents of the APK:

Content

Description

assemblies/System.*

These assemblies contain core .NET namespaces such as System.IO and System.Collection

assemblies/Mono.Android.dll

This assembly contains the Xamarin.Android binding classes

assemblies/NationalParks.Droid.dll

This assembly contains the classes we created: MainActivity, DetailActivity, and NationalParksAdapter

assemblies/Newtonsoft.Json.dll

This assembly contains the Json.NET classes

classes.dex

This file contains all the generated Java peer objects in a Dalvik-compiled format

lib/armeabi-v7a/libmonodroid.so

This is the Mono CLR for Android

res/*

This folder contains all the resources; drawables, layouts, menus, and so on

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset