devconsole
devconsole

Reputation: 7915

Android in-app billing: Is it really necessary to create a local service?

The official documentation says that "Your application must have a local Service to facilitate messaging between your application and Android Market."

My question is, is this is really necessary? And if yes, why?

Wouldn't it be possible to simply bind to the MarketBillingService from an Activity's onCreate method without having to creating a local service first?

Having to create a local service that forward the requests to the remote MarketBillingService just seems a bit over-complicated.

Upvotes: 2

Views: 502

Answers (1)

devunwired
devunwired

Reputation: 63293

I agree that the In-App Billing example application has a number of layers to it that seem unnecessary, but the idea of using a Service to interact with Market is a good one. This is because the process is very asynchronous (and can take a good amount of time) and some events are generated outside the workflow of a user purchase.

While the user will be interacting with some Market UI while deciding whether to purchase the "item", after this process is over there is a long back-and-forth between your app and the market app to authorize and finalize the transaction, many steps delayed while Market communicates with its servers. You don't want to hold the user up and force them to wait on that Activity simply so you can complete the purchase. You want that to be in a Service so the user can move around in the app, or leave it completely for awhile, and still be able to finalize the purchase and download the appropriate purchased content without fear of your process being removed.

Also, there are many events that may come into your application if purchases are canceled or otherwise rejected that can happen LONG after the initial purchase back-and-forth, and the user may be doing something completely different or not have their phone awake at all at that time. You want to be able to handle these events without having to pop up an Activity.

Bottom line, it's a long-running background process...which is what Services were designed for.

HTH

Upvotes: 2

Related Questions