使用在app app android中购买商品后屏幕未更新

时间:2014-07-28 07:03:34

标签: android in-app-purchase

我正在Android应用中实现应用内购买功能。当用户点击该项目时,它会在Google Play上显示该项目的价格。购买商品后,它不会更新屏幕(删除该商品上的购买图片并更新屏幕)。这是我的代码:

private static boolean buyUfo = false;
private static final String BUYUFO ="buyUfo";
private SharedPreferences sharedPreference; 
SharedPreferences.Editor editor ;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preference);
    sharedPreference = this.getSharedPreferences(SHARED_PREFERENCE_ID, MODE_PRIVATE);
    editor = sharedPreference.edit();
    buyUfo = sharedPreference.getBoolean(BUYUFO, false);
}

IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
        Log_Billing("InAppBilling", "get purchased items from service  result = " + result);
        if (mInappBillingHelper == null) {
            return;
        }

        // Is it a failure?
        if (result.isFailure()) {
            Log_Billing("InAppBilling", "get purchased items from service failed !!!!");
            return;
        }

        boolean hasItemBoughtdiscovered = false;
        Purchase ufoPurchase = inventory.getPurchase(getString(R.string.SKU_Ufo));
        if ((ufoPurchase != null && verifyDeveloperPayload(ufoPurchase))) {
            Log_Billing("InAppBilling", "User has bought UFO alreadly" + ufoPurchase);
            editor.putBoolean(BUYUFO, true);
            hasItemBoughtdiscovered = true;
            editor.commit();
            if(hasItemBoughtdiscovered) {
                updateSettingUi();
            }
        }
    }
};

我想在购买后使 buyUfo 成为现实。我的问题是,在InApp购买之后,是否调用了QueryInventoryFinishedListener?如果没有,那么调用哪个Listener?

1 个答案:

答案 0 :(得分:0)

您的活动的onResume()从共享偏好中获取值,如果为true,则检查是true还是false,即在您的活动中购买了更改的ui(图标)