0

I am creating the subscription purchase for an app. And I originally had something like this:

    // CREATE THE SUBSCRIBE BUTTON
    Button subscribe = (Button)findViewById(R.id.subscribe);
    subscribe.setOnClickListener(new Button.OnClickListener() 
    {  
      public void onClick(View v) 
      {             
          onUpgradeAppButtonClicked ( );
      }
    });                   

public void onUpgradeAppButtonClicked( ) 
{
    Log.d(TAG, "Buy button clicked; launching purchase flow for upgrade.");
    setWaitScreen(true);
    mHelper.launchPurchaseFlow(this, SKU_SUBSCRIPTION, RC_REQUEST, mPurchaseFinishedListener);
}

But then I read that the IABHelper needs to get set asynchronously. And that invoking this method from a button click might not be right.

But how does it possibly get invoked if not from a button click?

Thanks!

Genadinik
  • 18,153
  • 63
  • 185
  • 284

1 Answers1

1

I suppose what was meant is, that it will take some time, so you should run it asynchronously, so it does not freeze your UI. So, sure you'll invoke it from a button click, but not directly. Instead, in your onUpgradeAppButtonClicked() method, do something to run the mHelper.launchPurchaseFlow()... asynchronously, like using an AsyncTask or a separate Thread or the like.

The famous Painless Threading Article comes, as always, very handy for this.

Ridcully
  • 23,362
  • 7
  • 71
  • 86
  • thanks - but that is what I am currently doing....I think. Does that mean I am all set? :) Also, if they need to unsubscribe, should I just launch the same method? – Genadinik Apr 22 '13 at 18:29
  • Yes, I think you're all set then. As for unsubscribing I don't know, as I've never implemented in app billing myself. But basically I'd say, if it works, it's fine. – Ridcully Apr 22 '13 at 18:31