From f0a4073df9da640af14aa1269d4d7f8dd021acbf Mon Sep 17 00:00:00 2001 From: Michael Shafrir Date: Wed, 11 Sep 2019 09:24:40 -0400 Subject: [PATCH] Fix crash when Fragment is not attached Check that the fragment is attached before calling `startActivityForResult()`. Fixes #1517 --- .../main/java/com/stripe/android/view/AuthActivityStarter.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stripe/src/main/java/com/stripe/android/view/AuthActivityStarter.kt b/stripe/src/main/java/com/stripe/android/view/AuthActivityStarter.kt index d39ec2161b1..d703a068132 100644 --- a/stripe/src/main/java/com/stripe/android/view/AuthActivityStarter.kt +++ b/stripe/src/main/java/com/stripe/android/view/AuthActivityStarter.kt @@ -26,7 +26,9 @@ internal interface AuthActivityStarter { if (fragmentRef != null) { val fragment = fragmentRef.get() - fragment?.startActivityForResult(intent, requestCode) + if (fragment?.isAdded == true) { + fragment.startActivityForResult(intent, requestCode) + } } else { activity.startActivityForResult(intent, requestCode) }