I'm using a google provided code (IabHelper.java, etc.) to setup in-App billing in my Android App. The provided code is asynchronous in the sense that I need to specify a callback function that will fun upon successfully binding a service.
However, I found myself in a need to possess information about current subscriptions across different activities. So I decided to bind the billing service synchronously in onCreate method of the Activity and keep it in a static variable. This should be relatively fast since Google Play Services do some caching. The code I use is the following:
// this - current activity
CountDownLatch latch = new CountDownLatch(1);
mService = new BillingService(this, latch);
try {
latch.await();
} catch (InterruptedException ignored) {}
And then in onIabSetupFinished
I call latch.countDown()
. Unfortunately, countDown
is never get executed and my code is stuck in await()
. Does anyone know how to solve this or suggest an alternative solution?