diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieTask.java b/lottie/src/main/java/com/airbnb/lottie/LottieTask.java index a602ec707d..8a62b3b586 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieTask.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieTask.java @@ -137,18 +137,24 @@ public LottieResult getResult() { private void notifyListeners() { // Listeners should be called on the main thread. - handler.post(() -> { - // Local reference in case it gets set on a background thread. - LottieResult result = LottieTask.this.result; - if (result == null) { - return; - } - if (result.getValue() != null) { - notifySuccessListeners(result.getValue()); - } else { - notifyFailureListeners(result.getException()); - } - }); + if (Looper.myLooper() == Looper.getMainLooper()) { + notifyListenersInternal(); + } else { + handler.post(this::notifyListenersInternal); + } + } + + private void notifyListenersInternal() { + // Local reference in case it gets set on a background thread. + LottieResult result = LottieTask.this.result; + if (result == null) { + return; + } + if (result.getValue() != null) { + notifySuccessListeners(result.getValue()); + } else { + notifyFailureListeners(result.getException()); + } } private synchronized void notifySuccessListeners(T value) {