Listing 1110 Android Manifestxml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.cookbook.advance.rpc" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon"

android:label="@string/app_name" > <activity android:name=".rpc" android:label="@string/app_name"> <intent-filter>

<action android:name="android.intent.action. MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

<service android:name=".rpcService" android:process=".remoteService"/>

</application>

<uses-sdk android:minSdkVersion="7" /> </manifest>

The second activity is shown in Listing 11.11. It needs to call bindService() to retrieve the factorial() method provided in the rpcService.The bindService() requires a service connection instance as the interface for monitoring the state of an application service.Therefore, this activity has an inner class myServiceConnection that implements the service connection.

The myServiceConnection and IAdditionService classes are instantiated in the rpc activity. The myServiceConnection listens to the onServiceConnected and onServiceDisconnected callback functions.The onServiceConnected passes the IBinder instance to the IAdditionService instance.The onServiceDisconnected callback function puts the IAdditionService instance to null.

There are also two methods defined inside the rpc activity that are initService() and releaseService() .The initService() tries to initiate a new myServiceConnetion.Then, it creates a new intent for a specific package name and class name and passes it to the bindService along with the myServiceConnection instance and a flag BIND_AUTO_CREATE.After the service is bound, the onServiceConnected call back function is triggered and it passes the IBinder to the IAdditionService instance so the rpc activity can start to call the factorial method.The output is shown in Figure 11.3.

Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook


Post a comment