ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
appleService = IApple.Stub.asInterface(service);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
color = (EditText) findViewById(R.id.color);
weight = (EditText) findViewById(R.id.weight);
get = (Button) findViewById(R.id.get);
Intent intent = new Intent();
intent.setAction("AIDLSERVICETEST");
//绑定到远程服务上
bindService(intent, conn, Service.BIND_AUTO_CREATE);
get.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
color.setText(appleService.getColor());
weight.setText(appleService.getWeight()+"");
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
unbindService(conn);
super.onDestroy();
}
}
AIDL
最新推荐文章于 2024-06-28 12:28:59 发布