I am going through this tutorial they have: developer.android.com/guide/market/billing/billing_integrate.html
and I am in this section “Binding to the MarketBillingService”
They give those code snippets there:
try {
boolean bindResult = mContext.bindService(
new Intent("com.android.vending.billing.MarketBillingService.BIND"), this,
Context.BIND_AUTO_CREATE);
if (bindResult) {
Log.i(TAG, "Service bind successful.");
} else {
Log.e(TAG, "Could not bind to the MarketBillingService.");
}
} catch (SecurityException e) {
Log.e(TAG, "Security exception: " + e);
}
but I have no idea where to put them. Does it go in the Activity screen where the user presses the “buy” button? If so, what is the mContext object that they use? How do I unstantiate that? Is that like a button listener? Is this code meant to be in a button listener?
Thanks!
You put bindService code in the place where you want your app to start the Service, or to bind to the service. Typically, this would be in the onCreate or onStart of every Activity that interacts with the service. In this case, you put the code in the onCreate or onStart of the activity that has the “buy” button. I guess you could even put it in an async task that is started by the button.