Behind the scenes

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.

Peer object

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:

  • The MainActivity class extends android.app.Activity, which is what you would expect
  • An onCreate() proxy method is created that calls the native method n_onCreate(), which points to the overridden OnCreate() method in our managed C# class
  • The MainActivity 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()

The AndroidManifest.xml file

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>

Note the following points:

  • The target SDK is set to 15 in the <uses-sdk> element
  • The initial activity is set using the <category> element within the activity definition
..................Content has been hidden....................

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