kongzue il y a 3 ans
Parent
commit
94b135913c

+ 6 - 1
DialogX/src/main/java/com/kongzue/dialogx/interfaces/BaseDialog.java

@@ -55,6 +55,7 @@ import static com.kongzue.dialogx.DialogX.DEBUGMODE;
  */
 public abstract class BaseDialog {
     
+    protected static WeakReference<Thread> uiThread;
     private static WeakReference<FrameLayout> rootFrameLayout;
     private static WeakReference<Activity> contextWeakReference;
     protected WeakReference<Activity> ownActivity;
@@ -79,6 +80,7 @@ public abstract class BaseDialog {
     
     private static void initActivityContext(Activity activity) {
         try {
+            uiThread = new WeakReference<>(Thread.currentThread());
             contextWeakReference = new WeakReference<>(activity);
             rootFrameLayout = new WeakReference<>((FrameLayout) activity.getWindow().getDecorView());
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
@@ -604,7 +606,10 @@ public abstract class BaseDialog {
     public abstract String dialogKey();
     
     protected static void runOnMain(Runnable runnable) {
-        if (!DialogX.autoRunOnUIThread) runnable.run();
+        if (!DialogX.autoRunOnUIThread || (uiThread != null && Thread.currentThread() == uiThread.get())) {
+            runnable.run();
+            return;
+        }
         new Handler(Looper.getMainLooper()).post(runnable);
     }
     

+ 1 - 1
gradle.properties

@@ -18,5 +18,5 @@ android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
 android.enableJetifier=true
 
-BUILD_VERSION=0.0.44.debug7
+BUILD_VERSION=0.0.44.beta8
 BUILD_VERSION_INT=43