diff --git a/app/src/main/java/com/owncloud/android/services/OperationsService.java b/app/src/main/java/com/owncloud/android/services/OperationsService.java index 4cf151b3f77e..372a3c88e089 100644 --- a/app/src/main/java/com/owncloud/android/services/OperationsService.java +++ b/app/src/main/java/com/owncloud/android/services/OperationsService.java @@ -775,23 +775,24 @@ private User toUser(@Nullable Account account) { * @param operation Finished operation. * @param result Result of the operation. */ - protected void dispatchResultToOperationListeners( - final RemoteOperation operation, final RemoteOperationResult result - ) { + protected void dispatchResultToOperationListeners(final RemoteOperation operation, final RemoteOperationResult result) { int count = 0; - Iterator listeners = mOperationsBinder.mBoundListeners.keySet().iterator(); - while (listeners.hasNext()) { - final OnRemoteOperationListener listener = listeners.next(); - final Handler handler = mOperationsBinder.mBoundListeners.get(listener); - if (handler != null) { - handler.post(() -> listener.onRemoteOperationFinish(operation, result)); - count += 1; + + if (mOperationsBinder != null) { + for (OnRemoteOperationListener listener : mOperationsBinder.mBoundListeners.keySet()) { + final Handler handler = mOperationsBinder.mBoundListeners.get(listener); + if (handler != null) { + handler.post(() -> listener.onRemoteOperationFinish(operation, result)); + count += 1; + } } } + if (count == 0) { Pair undispatched = new Pair<>(operation, result); mUndispatchedFinishedOperations.put(operation.hashCode(), undispatched); } + Log_OC.d(TAG, "Called " + count + " listeners"); } }