Skip to content

Commit

Permalink
#13 Bugfix: Fix RuntimeException error when server has been killed.
Browse files Browse the repository at this point in the history
  • Loading branch information
codezjx committed Apr 18, 2022
1 parent 3729cd5 commit d77f891
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions andlinker/src/main/java/com/codezjx/andlinker/AndLinker.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void unbind() {
return;
}
mContext.unbindService(mServiceConnection);
handleUnBind();
handleUnBind(true);
}

/**
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit d77f891

Please sign in to comment.