I hope you realize that the service won't actually start until *after* the method on the main thread that started it exits. This is true even if you start up another thread to start the service. Starting the service -- even an IntentService -- requires that the main thread be free. (It's somewhat of a misnomer to call it the "UI thread", as it's used by all components, not just activities).
One consequence: This means you cannot access your service within the method that starts it. you could be deadlocking, or you could be getting (and ignoring) an error that results in incomplete initialization of your UI. The next time you play with this and it "locks up", use the debugger. See what code is running on the main thread. Whatever it is, that's what's blocking your UI. Everything on that thread should return quickly. Anything -- service, UI, anything -- that block that thread, blocks the entire application, UI and all. It's sort of the "system clock" of the entire application. If it's just in the Handler code waiting for something to do, then the problem isn't that your UI is blocked, but rather it wasn't fully set up. For example, handlers may not have been registered. Finally -- to address Dianne's point that 90% of programmers aren't good at thread programming: The other 10% know better to than to do thread programming themselves when a suitable alternative exists! On Apr 9, 12:20 pm, Jason LeBlanc <[email protected]> wrote: > Dianne, > > Thanks for the advice. AsyncTask seems to be a popular recommendation. For > some reason when I first read about it, I was turned away by the fact that > it could only be called once. I actually ordered a book on concurrency > yesterday, so hopefully I can get a better handle on multthreading. > > Mark, > > I took your advice and moved the Socket instantiation into the run() method. > Now it no longer locks up the UI thread. Thanks for that tidbit of wisdom. > > In the near future, I intend to create a small project to test the UI Thread > lockup from my splash screen. I'm still not sure why I couldn't thread the > start up of the service from the Activity and get the same results. > > Thanks, > J > > On Fri, Apr 9, 2010 at 12:54 PM, Dianne Hackborn <[email protected]>wrote: > > > > > I strongly recommend using IntentService, which takes care of the threading > > for you. Unless you are good at multithreading (I will claim that 90% of > > developers are not) then it is a good idea to stay away from Thread and use > > some higher-level facilities like IntentService, AsyncTask, etc. > > > On Fri, Apr 9, 2010 at 7:40 AM, Mark Murphy <[email protected]>wrote: > > >> Jason LeBlanc wrote: > >> > Yes, the Connection extends Thread. > > >> Then be sure not to do anything time-consuming in the Connection > >> constructor. Put the time-consuming stuff in run(). In this case, that > >> includes opening your socket connection, because while it might not be > >> time-consuming normally, it will be if it cannot resolve DNS, etc. > > >> > If I start a Thread in an Activity, does that Thread need to complete > >> > execution before I can transition to the next Activity? > > >> No. > > >> -- > >> Mark Murphy (a Commons Guy) > >>http://commonsware.com|http://twitter.com/commonsguy > > >> Warescription: Three Android Books, Plus Updates, One Low Price! > > >> -- > >> 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]<android-developers%2Bunsubs > >> [email protected]> > >> For more options, visit this group at > >>http://groups.google.com/group/android-developers?hl=en > > >> To unsubscribe, reply using "remove me" as the subject. > > > -- > > Dianne Hackborn > > Android framework engineer > > [email protected] > > > Note: please don't send private questions to me, as I don't have time to > > provide private support, and so won't reply to such e-mails. All such > > questions should be posted on public forums, where I and others can see and > > answer them. > > > -- > > 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]<android-developers%2Bunsubs > > [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

