private IAgent iAgent;
protected ServiceConnection agentConn = new ServiceConnection() {
@Override
synchronized public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
iAgent = IAgent.Stub.asInterface(iBinder);
Log.e("111","获得agent接口对象"+iAgent);
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
iAgent = null;
}
};
Intent PersonIntent = new Intent();
PersonIntent.setAction("com.example.sky000.aidlagent.AgentService");
PersonIntent.setPackage("com.example.sky000.aidlagent");
if (bindService(PersonIntent,agentConn, Context.BIND_AUTO_CREATE)){
Log.e("111", "绑定Person服务成功");
Log.e("111", String.valueOf(iAgent));
}
打印结果:第一行是绑定Person服务成功,第二上是null,第三行是"获得agent接口对象com.example.sky000.aidlserverdemo.IPerson$Stub$Proxy@568592
加了Thread.sleep(1000);之后也不能改变这两个的执行顺序, 我需要在绑定成功后得到IAgent对象