Skip to content

Commit

Permalink
Fix tailrec as this was not a tailrec function
Browse files Browse the repository at this point in the history
  • Loading branch information
wmontwe committed Jan 10, 2025
1 parent 04b95c6 commit 8b373bd
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

0 comments on commit 8b373bd

Please sign in to comment.