Android how do I wait until a service is actually connected?

How can I wait for
ServiceConnection.onServiceConnected
being called reliably?

You don’t. You exit out of onCreate() (or wherever you are binding) and you put you “needs the connection established” code in onServiceConnected().

Are all the event handlers:
Activity.onCreate, any
View.onClickListener.onClick,
ServiceConnection.onServiceConnected,
etc. actually called in the same
thread

Yes.

When exactly is
ServiceConnection.onServiceConnected
actually going to be called? Upon
completion of Activity.onCreate or
sometime when A.oC is still running?

Your bind request probably is not even going to start until after you leave onCreate(). Hence, onServiceConnected() will called sometime after you leave onCreate().

Leave a Comment