Nick
Nick

Reputation: 3435

android in-app purchases API 3

I'm trying to figure out how to implement in-app purchasing in my app that comprises a dozen of activities. The main question is where to put IABHelper m_helper; object? Everything is simple in case on single-activity app (like the sample "android-sdk\extras\google\play_billing\samples\TrivialDrive\src\com\example\android\trivialdrivesample").

But I need to interact with billing system from within several Activities. Is it cool to define a IABHelper m_helper; in each of them? I suspect no. If I define it only in my root activity, how do I access it from secondary activities? Moreover, look at a scenario like this:

  1. Start app.
  2. Root activity launches and billing system (IABHelper m_helper) setups.
  3. Go to secondary activity. Now I can access (somehow) root activity's m_helper because root activity is not destroyed yet.
  4. Press home button
  5. Launch a million of cool Android apps.
  6. Return back to my app. Secondary activity wakes up, but Root is killed by Android on step 5. I lost access to m_helper.

Am missing some Android concepts?

Upvotes: 0

Views: 517

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199825

IABHelper provides convenience methods for connecting an Activity to the billing Service. It is not a global connection, so you can certainly create one for each Activity that needs to read/write billing information.

However, make sure you only call m_helper.setup(this) once for each Activity (generally in the onCreate for that Activity). Similarly, only call m_helper.dispose() once per Activity (usually in the onDestroy method).

Upvotes: 1

Related Questions