项目中用到第三方开源的IM,以依赖moudle的形式引入,需要在Application中初始化,初始化时需要去绑定moudle中的ClientService服务,debug调试有进行bindSrvice()操作,代码如下
Intent intent = new Intent(gContext, ClientService.class);
intent.putExtra("clientId", getClientId());
boolean result = gContext.bindService(intent, serviceConnection, BIND_AUTO_CREATE);
private ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
mClient = IRemoteClient.Stub.asInterface(iBinder);
@Override
public void onServiceDisconnected(ComponentName componentName) {
Log.e("chatManager", "onServiceDisconnected");
mClient = null;
checkRemoteService();
mainHandler.post(() -> {
for (IMServiceStatusListener listener : imServiceStatusListeners) {
listener.onServiceDisconnected();
}
});
}
};
且result为true,但是在真机上并没有回调onServiceConnected()或者onServiceDisconnected()方法,但是在模拟器上有回调onServiceConnected()方法。