在使用 AsyncTask 的 doInBackground() 函数加载数据时,我按照本教程向我的应用程序的启动添加了加载屏幕。
我的应用程序还具有应用内计费高级升级功能,我想在发布时查询库存以检查此功能。但是,这些IabHelper
功能已经是异步的。
如何将IabHelper
检查集成到 doInBackground() 中,以便仅在一切成功完成后才加载主要活动?
我的计费代码如下:
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"));
}
}
};