From d77f891156a78c79b2a70aa4267ceb596cac6856 Mon Sep 17 00:00:00 2001 From: codezjx Date: Mon, 18 Apr 2022 11:20:28 +0800 Subject: [PATCH] #13 Bugfix: Fix RuntimeException error when server has been killed. --- .../java/com/codezjx/andlinker/AndLinker.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/andlinker/src/main/java/com/codezjx/andlinker/AndLinker.java b/andlinker/src/main/java/com/codezjx/andlinker/AndLinker.java index 26f917b..358e0f3 100644 --- a/andlinker/src/main/java/com/codezjx/andlinker/AndLinker.java +++ b/andlinker/src/main/java/com/codezjx/andlinker/AndLinker.java @@ -104,7 +104,7 @@ public void unbind() { return; } mContext.unbindService(mServiceConnection); - handleUnBind(); + handleUnBind(true); } /** @@ -166,21 +166,24 @@ public void onServiceConnected(ComponentName name, IBinder service) { @Override public void onServiceDisconnected(ComponentName name) { Logger.d(TAG, "onServiceDisconnected:" + name); - handleUnBind(); + handleUnBind(false); } }; } - private void handleUnBind() { + private void handleUnBind(boolean unRegister) { + Logger.d(TAG, "handleUnBind:" + unRegister); if (mTransferService == null) { Logger.e(TAG, "Error occur, TransferService was null when service disconnected."); fireOnUnBind(); return; } - try { - mTransferService.unRegister(mCallback); - } catch (RemoteException e) { - e.printStackTrace(); + if (unRegister) { + try { + mTransferService.unRegister(mCallback); + } catch (RemoteException e) { + e.printStackTrace(); + } } mTransferService = null; fireOnUnBind();