Bill Michaelson wrote: > I do a ((Context)thingy).bindService(...) from within the onCreate > callback of an Activity. I've observed that the onServiceConnected() > callback of my associated ServiceConnection does not execute > immediately, but rather, is delayed until after the Activity resumes, > or more precisely, after return from the onResume() callback of the > Activity. > > I discovered this the hard way (through a null pointer exception) > because I was unable to use the Service (I call a method in the > Service to start a Thread) immediately upon return from the bindService > () call. > > I assume this is normal behavior, but I don't understand why, and I > further assume that there is a good reason for it and that I would > benefit from understanding it.
bindService() is asynchronous. AFAIK, it puts a message on the message queue that the main thread processes, saying "hey! please bind me to this service!". However, the logic to call onStart() and onResume() is probably already on that queue, so they'll get processed first. Regardless, you should not really assume much about the timing of when onServiceConnected() gets called. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Development Wiki: http://wiki.andmob.org
-- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en