"
onServiceConnected时异常如下:
崩溃线程
java.lang.ClassCastException: android.os.BinderProxy cannot be cast to com.ayst.healthkit.cq at com.ayst.healthkit.bp.onServiceConnected(MainActivity.java:492) at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1140) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1157) at android.os.Handler.handleCallback(Handler.java:808) at android.os.Handler.dispatchMessage(Handler.java:103) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5292) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) at dalvik.system.NativeStart.main(Native Method)
Activity代码:
ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
Common.debug(TAG, "onServiceDisconnected");
mUsbService = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Common.debug(TAG, "onServiceConnected");
mUsbService = ((UsbTransferServer.UsbBinder)service).getService();
}
};
Service代码:
@Override
public IBinder onBind(Intent intent) {
return new UsbBinder();
}
public class UsbBinder extends Binder {
public UsbTransferServer getService(){
return UsbTransferServer.this;
}
}
注:上面异常是偶现问题,测试50次出现过2次;
" ![image.png](https://ucc.alicdn.com/pic/developer-ecology/55bd84d6877d4c19ab0a74b891fbcb16.png)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。