Question

I was confused with the order that which function Activate function or bind function gets called when component become active. In my opinion activate function function will be called first as Bind function is for binding the service. But as we know that all the target service are first get into the component context then component gets activated.

Please clear my doubt.

Was it helpful?

Solution

The activate method will be called after all the static references have been bound, i.e. after the bind methods have been called. So during the activate, you can be sure that the value of the static references will not change.

However for dynamic references, all bets are off. In fact the value of a dynamic reference could change multiple times in different threads, during the execution of the activate method.

UPDATE: You didn't ask about deactivation, but you might find this information useful all the same. The deactivate method will be called before any static reference is unbound. So for example: if you were bound to a service with a static reference and the service you were bound to goes away, then SCR will first call your deactivate, then your unbind method(s), and finally it will free the component instance for garbage collection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top