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 -- 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

