Listing 1111 srccomcookbookadvancerpcrpcjava

package com.cookbook.advance.rpc;


import android.content.ComponentName;

import android.content.Context;

import android.content.Intent;

import android.content.ServiceConnection;

import android.os.Bundle;

import android.os.IBinder;

import android.os.RemoteException;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Toast;

public class rpc extends Activity {

IAdditionService service; myServiceConnection connection;

class myServiceConnection implements ServiceConnection {

public void onServiceConnected(ComponentName name,

IBinder boundService) { service = IAdditionService.Stub.asInterface((IBinder) boundService);

Toast.makeText(rpc.this, "Service connected", Toast.LENGTH_SHORT) •show();

public void onServiceDisconnected(ComponentName name) { service = null;

Toast.makeText(rpc.this, "Service disconnected", Toast.LENGTH_SHORT) •show();

private void initService() {

connection = new myServiceConnection(); Intent i = new Intent();

i.setClassName("com.cookbook.advance.rpc", com.cookbook.advance.rpc.rpcService.class.getName()); if(!bindService(i, connection, Context.BIND_AUTO_CREATE)) {

Toast.makeText(rpc.this, "Bind Service Failed", Toast.LENGTH_LONG) •show();

private void releaseService() { unbindService(connection); connection = null;

^Override public void onCreate(Bundle savedlnstanceState) { super.onCreate(savedlnstanceState); setContentView(R.layout.main);


Button buttonCalc = (Button) findViewByld(;

buttonCalc.setOnClickListener(new OnClickListener() { TextView result = (TextView) findViewByld(; EditText valuel = (EditText) findViewByld(;

public void onClick(View v) { int vl, res = -1; try {

vl = Integer.parseInt(value1.getText().toString()); res = service.factorial(vl); } catch (RemoteException e) { e.printStackTrace();

result.setText(new Integer(res).toString());

@Override protected void onDestroy() { releaseService();

Figure 11.3 Output of the AIDL application.
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