It is interesting at this point to take a quick look at a few of the things that go on behind the scenes, which we previously discussed.
Let's start with the peer object (proxy object) discussed in Chapter 2, Xamarin.Android Architecture. Navigate to POIAppPOIAppobjDebugandroidsrcpoiapp
in the code bundle in Windows XP and open MainActivity.java
using Notepad. The following code listing depicts some of the key pieces of the source file:
package poiapp; public class MainActivity extends android.app.Activity implements mono.android.IGCUserPeer { . . . public void onCreate (android.os.Bundle p0) { n_onCreate (p0); } private native void n_onCreate (android.os.Bundle p0); . . . }
Note the following points:
MainActivity
class extends android.app.Activity,
which is what you would expectonCreate()
proxy method is created that calls the native method n_onCreate()
, which points to the overridden OnCreate()
method in our managed C# classMainActivity
class has a static initializing block and a constructor that establishes the link between the Java class and it's managed C# peer, including initializing n_onCreate()
Navigate to POIAppPOIAppobjDebugandroid
in the code bundle and open the AndroidManifest.xml
file. The following code listing depicts a portion of the manifest file:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="POIApp.POIApp"> <uses-sdk android:minSdkVersion="15" /> <application android:label="POIApp" android:name="mono.android.app.Application" android:debuggable="true"> <activity android:label="POIs" android:name="poiapp.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> . . . </application> <uses-permission android:name="android.permission.INTERNET" /> </manifest>
15
in the <uses-sdk>
element<category>
element within the activity definition18.118.16.229