Răsfoiți Sursa

Added UI thread check when showing dialog

Aidan Follestad 10 ani în urmă
părinte
comite
1b8ae302c2

+ 7 - 0
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -13,6 +13,7 @@ import android.graphics.Rect;
 import android.graphics.Typeface;
 import android.graphics.drawable.Drawable;
 import android.os.Build;
+import android.os.Looper;
 import android.support.annotation.ArrayRes;
 import android.support.annotation.AttrRes;
 import android.support.annotation.ColorRes;
@@ -1254,6 +1255,12 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         }
     }
 
+    @Override
+    public void show() {
+        if(Looper.myLooper() != Looper.getMainLooper())
+            throw new IllegalStateException("Dialogs can only be shown from the UI thread.");
+        super.show();
+    }
 
     private ColorStateList getActionTextStateList(int newPrimaryColor) {
         final int fallBackButtonColor = DialogUtils.resolveColor(getContext(), android.R.attr.textColorPrimary);