diff --git a/core/android/common/src/main/kotlin/app/k9mail/core/android/common/activity/ContextExtensions.kt b/core/android/common/src/main/kotlin/app/k9mail/core/android/common/activity/ContextExtensions.kt index 67767acc8ab..f2a929477f8 100644 --- a/core/android/common/src/main/kotlin/app/k9mail/core/android/common/activity/ContextExtensions.kt +++ b/core/android/common/src/main/kotlin/app/k9mail/core/android/common/activity/ContextExtensions.kt @@ -7,5 +7,10 @@ import android.content.Context import android.content.ContextWrapper // Source: https://stackoverflow.com/a/58249983 -tailrec fun Context.findActivity(): Activity? = this as? Activity - ?: (this as? ContextWrapper)?.baseContext?.findActivity() +tailrec fun Context.findActivity(): Activity? { + return if (this is Activity) { + this + } else { + (this as? ContextWrapper)?.baseContext?.findActivity() + } +}