对上一篇的proxy模式中提到的例子进行优化如下:
package com.sean.mp3player;
import android.os.Binder;
import android.os.IBinder;
import android.os.Parcel;
import android.os.RemoteException;
public interface IPlayer1 {
public void play();
public void stop();
public void getStatus();
public static abstract class Stub extends Binder implements IPlayer1 {
@Override
protected boolean onTransact(int code, Parcel data, Parcel reply,
int flags) throws RemoteException {
// TODO Auto-generated method stub
if (code == 1) {
this.play();
} else if (code == 2) {
this.stop();
} else if (code == 3) {
this.getStatus();
}
return true;
}
public abstract void play();
public abstract void stop();
public abstract void getStatus();
public static IPlayer1 asInterface(IBinder binder) {