In my current Android Project, I am starting a Service via startService()
, then afterwards I am binding to the Service with bindService()
. (I do this because I want to have a started Service I am able to communicate with, nevermind)
After the Context is bound to the Service, usually onServiceConnected()
of my ServiceConnection
(wich I created earlier) is called if i understood this right.
Can I assume, that onServiceConnected()
is only called after all of my code in the onCreate
of my Service is executed?
Yes you can.
According to the service lifecycle diagram
onBind()
is not called until afteronCreate()
has completed.The documentation states that the system calls
onServiceConnected()
to deliver theIBinder
returned by the service'sonBind()
method.Therefore
onCreate()
is completed beforeonServiceConnected()
is called since it is dependent on the return value ofonBind()
which occurs afteronCreate()
. You can also see this in the diagram where it says "Clients are bound to service".