> This result might (I'm speculating) be because the onCreate() methods > of the Activity and the Service are guaranteed to complete in their > lifecycle. So maybe Android only lets one of them run at a time?
This is very true. Since the Service runs in the UI thread, along with the Activity, all that is really happening is that a message is being sent to start the Service. It isn't actually started until you have left the Activity and the UI thread gets around to processing the messaging queue and starts the Service. On Nov 3, 4:56 pm, jotobjects <[email protected]> wrote: > What I discovered was the locus of my problem is that if you call > bindService() from either Activity.onCreate() or Activity.onStart() > then bindService() will return "true" indicating the Service is bound > to the Activity BUT the Service will NOT have been constructed and the > Service onCreate() method will NOT have been called. > > This is a little non-intuitive since you would think that if the > Service is bound, then service would at least exist. But in fact it > might not even exist yet! > > This result might (I'm speculating) be because the onCreate() methods > of the Activity and the Service are guaranteed to complete in their > lifecycle. So maybe Android only lets one of them run at a time? > > On Nov 2, 4:57 pm, jotobjects <[email protected]> wrote: > > > > > On Nov 2, 2:43 pm, Kostya Vasilyev <[email protected]> wrote: > > > > Services are a mechanism for doing tasks that take a long time (among > > > another things). Based on this, the result of a service doing something > > > is typically available after a delay, so services are asynchronous by > > > their nature. > > > Right. Long running tasks have asynchronous results. That's why you > > put them in a Service (and run the actual tasks in a thread). > > > > If you have a piece of code that you wish to run synchronously, just > > > call that code directly (remembering to avoid code that can lead to ANRs). > > > > The only time I can see synchronous start / bind could be useful is > > > updating an Activity with the current state of some process managed by a > > > service. > > > Right, that's 101 as Frank said. I'm not trying to do anything > > synchronously. But what tripped me up was that I have new work for > > the Service to do from time to time based on other things going on in > > the application. There is no way to actually know when the Service > > exists. So you can't reliably communicate with the Service EXCEPT via > > Intents with startService (as Mark pointed out) or somehow with the > > ServiceConnection by deferring communication with the servie until > > after onServiceConnected(0 is called. > > > Some of the Local Service examples out there can lead one to believe > > that the service can be used directly and that's not true. > > > > But even this case should work pretty well, because at the time onCreate > > > is called (and presumable, that's where service start / bind is called), > > > the activity is not fully visible yet (since its content view is only > > > specified inside onCreate). > > > > -- Kostya > > > > 03.11.2010 0:30, jotobjects пишет: > > > > > On Nov 2, 1:33 pm, Frank Weiss<[email protected]> wrote: > > > >> GUI Programming 101 > > > > >> All GUIs I've seen use an event queue. This is one of the biggest > > > >> prardigm > > > >> shifts to overcome for someone who is used to sequential, non-GUI > > > >> applications. > > > > The Service object by definition has nothing to with GUI programming, > > > > but you sort of have the right idea. > > > > -- > > > Kostya Vasilyev -- WiFi Manager + pretty widget > > > --http://kmansoft.wordpress.com- Hide quoted text - > > - Show quoted text - -- 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

