I start an AsyncTask when my apps start so that user premium features will be show right away. But i am not getting info passed from doInBackground (the values after the query) to onPostExecute.
I do a queryInventoryAsync that defines values are true or false then I use this values on fragment to diverse actions.
public class LoadAppBilling extends AsyncTask <Result, Result, Result> {
static final String SKU_PREMIUMV = "test.hsdbgjfasbdfughvakcshfgb";
static final String SKU_NO_ADDS = "test.blah";
static final String TAG = "Azores Bus Premium";
IabHelper mHelper;
boolean mPremiumV = false;
boolean mAdds = false;
IabHelper.QueryInventoryFinishedListener mGotInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
Log.d(TAG, "didnt load");
return;
}
Log.d(TAG, " load");
if (inventory.hasPurchase(SKU_PREMIUMV)) {
mPremiumV = true;
return;
}
if (inventory.hasPurchase(SKU_NO_ADDS)) {
mAdds = true;
}
}
};
@Override
public Result doInBackground(Result... params) {
String base64EncodedPublicKey = "";
Log.d(TAG, "Creating IAB helper.");
mHelper = new IabHelper(getApplication(), base64EncodedPublicKey);
mHelper.enableDebugLogging(true);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh noes, there was a problem.
Log.d(TAG, "Problem setting up In-app Billing: " + result);
}
// Hooray, IAB is fully set up!
mHelper.queryInventoryAsync(mGotInventoryListener);
}
});
return null;
}
@Override
public void onPostExecute(Result result) {
}
}
and then in fragment i call
new LoadAppBilling() {
@Override
public void onPostExecute (Result result) {
super.onPostExecute(result);
if (mPremiumV) {
//open a fragment
} else {
// show a dialog
}}
}
.execute();
break;