'Play Billing v4 - Checking if SKU is purchased on onCreate

I am trying to make a donation iap that unlocks different themes for the app. Because of that, I am trying to query if the donation SKU is purchased before setting the content view. Is that possible? I've tried this so far:

fun onCreate(savedInstanceState: Bundle?){
    billingRepository.isPurchased(SKU_COFFEE).observe(this){ premium: Boolean ->
        if(premium) setTheme(requestedTheme)
        _binding = ...
        setContentView(binding.root)
    }
}

But this leads to ANRs when the phone doesn't have access to Internet.

(The billingRepository is the one that comes from the Trivial Drive sample made by Google.)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source