meetings
meetings
2016-09-12 02:31
采纳率: 30%
浏览 2.5k
已采纳

安卓中AIDL里面onServiceConnected和bindService两个函数执行顺序的问题

     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对象

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

相关推荐