求助大神,关于安卓aidl远程服务通信

bindService返回true可是我实现ServiceConnection的myService为空。下面是我的客服端代码
public class MainActivity extends AppCompatActivity {
private Intent services;
private IService myService;
private MyConnection connection;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    services = new Intent();
    services.setAction("com.wangjiang.studentinfomationservice");
    services.setPackage("com.wangjiang.studentinfomationservice");
    connection = new MyConnection();
    boolean t = bindService(services, connection, BIND_AUTO_CREATE);
    Toast.makeText(MainActivity.this, String.valueOf(t),Toast.LENGTH_LONG).show();
    try {
        if(myService !=null) {
            List<Student> list =myService.getData();
            if(list != null)
                Toast.makeText(MainActivity.this,"list.size() + " , Toast.LENGTH_LONG).show();
            else
                Toast.makeText(MainActivity.this, "NULL" , Toast.LENGTH_LONG).show();
        } else
            Toast.makeText(MainActivity.this, "NU" , Toast.LENGTH_LONG).show();
    } catch (RemoteException e) {
        e.printStackTrace();
    }

    unbindService(connection);
}

private class MyConnection implements ServiceConnection {

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        if (service == null)
            Log.i("CLIENT","bind null");
        else {
            myService = IService.Stub.asInterface(service);
            Log.i("CLIENT","bindetr");
        }
    }

    @Override
    public void onServiceDisconnected(ComponentName name) {

    }
}

}

1个回答

qq_29733087
S-lience 感激不尽
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问