[android-developers] Re: Service operation
Aha. That makes perfect sense. It hadn't occurred to me that the
scheduling might work that way, so you've substantially improved my
perspective. Thank you.
As to assumptions about timing, point taken. Async is async. And I
had assumed that return from bindService would guarantee completion of
certain initialization. Apparently not, so then I will need to assure
startup somehow before relying on the Service's presence. Something
to consider tomorrow...
On Jan 12, 8:36 pm, Mark Murphy <mmur...@commonsware.com> wrote:
> 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
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home