From d06b14933dfccf7bc70784c31420cbc7e4053e57 Mon Sep 17 00:00:00 2001 From: Julian Winkler Date: Sun, 6 Oct 2024 11:16:55 +0200 Subject: [PATCH] delay Dialog.dismiss() by 10ms to work around NewPipe race condition --- src/api-impl/android/app/Dialog.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/api-impl/android/app/Dialog.java b/src/api-impl/android/app/Dialog.java index b3d169e2..3aa220ab 100644 --- a/src/api-impl/android/app/Dialog.java +++ b/src/api-impl/android/app/Dialog.java @@ -93,14 +93,18 @@ public class Dialog implements Window.Callback, DialogInterface { public void dismiss() { System.out.println("dismissing the Dialog " + Dialog.this); - new Handler(Looper.getMainLooper()).post(new Runnable() { + // HACK: dismissing the Dialog takes some time in AOSP, as the request goes back and forth between the application + // and the system server. We replicate this behavior by adding 10 ms delay. + // This Hack is required for NewPipe RouterActivity which has a race condition. It subscribes an rxJava observable + // and immediately calls Dialog.dismiss(). The OnDismissListener would unsubscribes the observable again. + new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { nativeClose(nativePtr); if (onDismissListener != null) onDismissListener.onDismiss(Dialog.this); } - }); + }, 10); } public Window getWindow() {