SilenceWangJiang 2017-04-16 02:23 采纳率: 0%
浏览 797
已采纳

求助大神,关于安卓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条回答 默认 最新

  • devmiao 2017-04-16 07:22
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 通联支付网上收银统一下单接口
  • ¥15 angular有偿编写,
  • ¥15 centos7系统下abinit安装时make出错
  • ¥15 hbuildex运行微信小程序报错
  • ¥15 关于#python#的问题:我知道这个问题对你们来说肯定so easy
  • ¥15 wpf datagrid如何实现多层表头
  • ¥15 为啥画版图在Run DRC会出现Connect Error?可我Calibre的hostname和计算机的hostname已经设置成一样的了。
  • ¥20 网站后台使用极速模式非常的卡
  • ¥20 Keil uVision5创建project没反应
  • ¥15 mmseqs内存报错