WEB开发网
开发学院手机开发Android 开发 Android AIDL必看内容 阅读

Android AIDL必看内容

 2010-05-27 03:49:00 来源:WEB开发网   
核心提示:super.onCreate(savedInstanceState);setContentView(R.layout.remote_service_binding);// Watch for button clicks.Button button = (Button)findViewById(R.id.bind);bu

super.onCreate(savedInstanceState);

setContentView(R.layout.remote_service_binding);

// Watch for button clicks.

Button button = (Button)findViewById(R.id.bind);

button.setOnClickListener(mBindListener);

button = (Button)findViewById(R.id.unbind);

button.setOnClickListener(mUnbindListener);

mKillButton = (Button)findViewById(R.id.kill);

mKillButton.setOnClickListener(mKillListener);

mKillButton.setEnabled(false);

mCallbackText = (TextView)findViewById(R.id.callback);

mCallbackText.setText("Not attached.");

}

/**

* Class for interacting with the main interface of the service.

*/

private ServiceConnection mConnection = new ServiceConnection() {

public void onServiceConnected(ComponentName className,

IBinder service) {

// This is called when the connection with the service has been

// established, giving us the service object we can use to

// interact with the service. We are communicating with our

// service through an IDL interface, so get a client-side

// representation of that from the raw service object.

mService = IRemoteService.Stub.asInterface(service);

mKillButton.setEnabled(true);

mCallbackText.setText("Attached.");

// We want to monitor the service for as long as we are

// connected to it.

try {

mService.registerCallback(mCallback);

} catch (RemoteException e) {

// In this case the service has crashed before we could even

// do anything with it; we can count on soon being

// disconnected (and then reconnected if it can be restarted)

// so there is no need to do anything here.

}

// As part of the sample, tell the user what happened.

上一页  1 2 3 4 5 6  下一页

Tags:Android AIDL

编辑录入:coldstar [复制链接] [打 印]
赞助商链接