If I try binding to a Service using Context.bindService()
, and that Service isn't already running/started, will I be guaranteed that the onCreate
of that Service will definitely be called before onBind
? I wasn't able to find any docs on the lifecycle of a Service, at least with respect to this question of which one of these two comes first.
If not, in which cases will onCreate
be called before onBind
? In the tests I've done, onCreate
always seems to be called before onBind
. But I need to be sure of this because I have some logic that could possibly fail if this order changes
In case it helps, I'm binding to this service to get a Messenger
that I will be sending messages to. So practically, my question is "can I be assured that onCreate
will execute before any of my messages get handled by the service?"
The onCreate
will be called first. It will not be called if the Service
is already running.
Service overview docs
Bounded Service overview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With