Prior to wrapping this chapter up, let's look at some of the things that go on behind the scenes.
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
.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.MainActivity
registers all the native methods for use with JNI using the mono.android.Runtime.register()
method.mono.android.TypeManager.Activate()
method.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:
<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.INTERNET
is specified. This came from the AndroidManifest.xml
file in the NationalParks.Droid/Properties
folder.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:
The following screenshot shows the contents of the resulting APK:
The following table provides a description of the contents of the APK:
Content |
Description |
---|---|
|
These assemblies contain core .NET namespaces such as |
|
This assembly contains the Xamarin.Android binding classes |
|
This assembly contains the classes we created: |
|
This assembly contains the Json.NET classes |
|
This file contains all the generated Java peer objects in a Dalvik-compiled format |
| |
|
This folder contains all the resources; drawables, layouts, menus, and so on |