Generally using something like the `Service()` constructor is a very bad idea. Doing so means that the service, receiver, etc... won't be hooked into the framework (which calls methods as appropriate on the object).
`#attachBaseContext` allows you to set the `Context` object through which calls will be delegated, but it is quite low level. As you may be aware, when you are executing in object, you typically have some `Context` object under you which allows you to do things like start activities, check permissions, etc... Of course, `Context` is simply this abstract thing that you can't really touch (the implementation is actually somewhere else, in '/android/app/ContextImpl.java' in the source tree. Instead, in this case, you are making a service and attaching the context manually, but then not really using the "service" features of the BillingService class, you're mostly using it to organize your code and make calls to the underlying billing service (the market billing service) to which you make calls through the BillingService class. Slightly odd and nonstandard use of a Service to organize the app design, but still useful. FYI this is the first time I've looked at in app billing, so this might be lacking some insight about how things are supposed to work. kris On Wed, Oct 31, 2012 at 9:32 PM, NoraBora <[email protected]> wrote: > I'm looking at the In-app Billing example and found something interesting. > ( > http://developer.android.com/guide/google/play/billing/billing_integrate.html#billing-download > ) > > I have known that Service must be started with startService() or > bindService(), > but in the example BillingService is made by BillingService() constructor > which I've never seen before. > > In the BillingService.java I found the comment "on behalf of the > application" and attachBaseContext(). > I guess maybe this is the reason? (I don't fully understand what > attachBaseContext() does, but the name tells me.) > Please give me some explanation. > > BTW, is using Service() constructor permitted / encouraged by any means? > This seems to me like Activity myActivity = new MyActivity() :( > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

