Exemplo n.º 1
0
  /**
   * Reads the set of purchased items from the database in a background thread and then adds those
   * items to the set of owned items in the main UI thread.
   */
  private void doInitializeOwnedItems() {
    Cursor cursor = mPurchaseDatabase.queryAllPurchasedItems();
    if (cursor == null) {
      return;
    }

    final Set<String> ownedItems = new HashSet<String>();
    try {
      int productIdCol = cursor.getColumnIndexOrThrow(PurchaseDatabase.PURCHASED_PRODUCT_ID_COL);
      while (cursor.moveToNext()) {
        String productId = cursor.getString(productIdCol);
        ownedItems.add(productId);
      }
    } finally {
      cursor.close();
    }

    // We will add the set of owned items in a new Runnable that runs on
    // the UI thread so that we don't need to synchronize access to
    // mOwnedItems.
    mHandler.post(
        new Runnable() {
          public void run() {
            mOwnedItems.addAll(ownedItems);
            mCatalogAdapter.setOwnedItems(mOwnedItems);
          }
        });
  }
Exemplo n.º 2
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   mPurchaseDatabase.close();
   mBillingService.unbind();
 }