What is the proper way to get the activity in a pu...
# compose
t
What is the proper way to get the activity in a pure compose world for the external things that requires it like Play Billing?
a
Something like this plus `LocalContext.current`:
Copy code
fun Context.findActivity(): Activity {
    var context = this
    while (context is ContextWrapper) {
        if (context is Activity) return context
        context = context.baseContext
    }
    error("Activity cannot be reached from $this")
}
t
Thanks, no risk of infinite recursion to handle?
a
No recursion here so no 🙂 but no, it won't loop infinitely either
t
Lol yes you get the idea 🙂 Thanks for the details.