From 0405d39ffbbc821ee74e99cabf6c746ef8b820f7 Mon Sep 17 00:00:00 2001 From: Majed DH Date: Sun, 7 Apr 2019 21:51:20 +0300 Subject: [PATCH] fix IllegalStateException when view is not attached. --- .../materialshowcaseview/MaterialShowcaseView.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java b/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java index 99fc13d2..a8761645 100644 --- a/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java +++ b/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java @@ -992,8 +992,14 @@ public boolean show(final Activity activity) { mHandler.postDelayed(new Runnable() { @Override public void run() { - - if (mShouldAnimate) { + boolean attached; + // taken from https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/core/src/main/java/androidx/core/view/ViewCompat.java#3310 + if (Build.VERSION.SDK_INT >= 19) { + attached = isAttachedToWindow(); + } else { + attached = getWindowToken() != null; + } + if (mShouldAnimate && attached) { fadeIn(); } else { setVisibility(VISIBLE);