Reputation: 3435
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:
IABHelper m_helper
) setups. m_helper
because root activity is not destroyed yet.m_helper
.Am missing some Android concepts?
Upvotes: 0
Views: 517
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