When to start and stop In-App Billing service?
A simple question, t开发者_StackOverflow社区hat I however can't resolve: when should I start and stop the billing service? I'm thinking about two decisions:
- starting in onCreate and stopping in onDestroy
- starting in onResume and stopping in onPause
What is the best practice? Thanks in advance.
I would suggest having your billing service derive from IntentService so that it will be started/stopped automatically when it needs to be. You start it using startService(Intent), and then when it's finished with it's work it will shut itself down. IntentService also provides built in queue so only one intent will be processed at once, and it's own worker thread.
As I recall, you also need a Receiver to use IAB, which could then call the service with an Intent, and have the action set based on what needs to be done.
精彩评论