Is onServiceConnected called only after the onCreate service?

In my current Android project, I start the service through startService() , after which I bind to the Service using bindService() . (I do this because I want to have a started Service with which I can communicate, no matter)

After the context is tied to the Service, usually the onServiceConnected() my ServiceConnection (which I created earlier) is called if I understood it correctly.

Is it possible to assume that onServiceConnected() is called only after all my code in onCreate my Service is executed?

+6
source share
1 answer

Is it possible to assume that onServiceConnected () is called only after all my code in onCreate of my service is executed?

Yes, you can.

According to the lifecycle diagram, the onBind() not called until onCreate() .

The documentation states that the system calls onServiceConnected() to deliver the IBinder returned by the onBind() service method.

Therefore, onCreate() completed before onCreate() is called, since it depends on the return value of onBind() , which occurs after onCreate() . You can also see this on the chart, which says: "Customers are required to service."

+3
source

All Articles