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
Adam Powell
06/25/2021, 5:29 PM
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
Tolriq
06/25/2021, 6:11 PM
Thanks, no risk of infinite recursion to handle?
a
Adam Powell
06/25/2021, 6:53 PM
No recursion here so no 🙂 but no, it won't loop infinitely either
t
Tolriq
06/25/2021, 7:56 PM
Lol yes you get the idea 🙂 Thanks for the details.