Reputation: 6732
I’d like to use the Google Play Billing Library for in-app billing in my Android app. When the app launches, I’d like to initialize the BillingClient, start the connection, and retrieve some product data. The actual purchase would happen from a different activity (not the launch activity).
Should I make some kind of singleton billing manager that contains the BillingClient, so I can start it when the app launches and still use it in the other activity? Or is there a better approach?
Upvotes: 5
Views: 2945
Reputation: 92
You can try following approach:
mBillingManager = new BillingManager(this, getUpdateListener());
mBillingManager.startServiceConnection(new Runnable() {
@Override
public void run() {
// Do AnyThing Here
}
});
Upvotes: 0
Reputation: 6569
There is an example provided by Google. In this example, they use additional BillingManager
class which can be accessed from different places of your application but it isn't a singleton because it's not only about BillingClient
you also have to have PurchasesUpdatedListener
which is receiving updates from the BillingManager
.
If you want to make BillingClient
a singleton you can use BillingManager from the sample app and manage the list of BillingUpdatesListener
by yourself.
Upvotes: 3