title: In-app billing query inventory in AsyncTask?
body: <p>I followed <a href="http://www.41post.com/4650/programming/android-coding-a-loading-screen-part-3" rel="nofollow">this tutorial</a> to add a loading screen to the launch of my app while data is loaded with AsyncTask's doInBackground() function.</p>
  
  <p>My app also features an in-app billing premium upgrade and I would like to query the inventory to check for this on launch.  However the <code>IabHelper</code> functions are already asynchronous.</p>
  
  <p>How can I integrate the <code>IabHelper</code> checks into doInBackground() so that the main activity is only loaded when everything has successfully completed?</p>
  
  <p>My billing code is as follows:</p>
  
  <pre><code>private void checkForPremiumPurchase()
  {
      billingHelper = new IabHelper(this, Constants.BASE_64_KEY);
      //Start setup. This is asynchronous and the specified listener will be called once setup completes.
      billingHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
          public void onIabSetupFinished(IabResult result) {
              if(result.isSuccess()) {
                  billingHelper.queryInventoryAsync(mGotInventoryListener);
              }
          }
      });
  }
  
  //Listener that's called when we finish querying the items and subscriptions we own
  IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener()
  {
      @Override
      public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
          if(result.isSuccess()) {
              isPremium = inventory.hasPurchase(Constants.SKU_PREMIUM);
              Log.d(Constants.TAG, "App is " + (isPremium ? "PREMIUM" : "NOT PREMIUM"));
          }
      }
  };
  </code></pre>