Thursday, April 24, 2014

The difference on the Service or bindService of startService


References:

Service can not run their own, need a way to start the service by calling Context.startService () or Context.bindService (). Both methods can be activated Service, but their use is different occasions. Use startService () method to enable the service, not related between the caller and the service, even if the caller exits, the service is still running. Use bindService () method to enable the service, the caller and the service is bound together, the caller once quit the service will terminate, great "while not seeking students must also die" features.
If you intend to use Context.startService () method to start the service, when the service is not created, the system will first call the onCreate () method of the service, then call onStart () method. If you call startService () method before the service has been created, multiple calls startService () method does not result in multiple created, but will lead to multiple calls onStart () method. Using startService () method to start the service, can only be called Context.stopService () method to end service calls onDestroy () method at the end of the service.
If you intend to use Context.bindService () method to start the service, when the service is not created, the system will first call the service's onCreate () method, then call onBind () method. This time the caller and services bundled together, out of the caller, the system will first call the service onUnbind () method, then calling onDestroy () method. If you call bindService () method before the service has been bound, repeatedly calling bindService () method does not result in multiple services and to create binding (ie onCreate () and onBind () method will not be called multiple times ). If the caller is bound to hope and unbinding service, you can call unbindService () method, call the method will lead to invoke services onUnbind () System -> onDestroy () method.

bindService () method when you start calling process: OnCreate () - onBind ()
If you call bindService () method before the service has been bound, repeatedly calling bindService () method does not result in multiple services and to create binding (ie onCreate () and onBind () method will not be called multiple times).
This sentence. . . If multiple calls will not go oncreate () and onBind () it? ? ? Should call onBind (), right? ? ? ?
Because, according to Context.startService () method to start the service, If you call startService () method before the service has been created, multiple calls startService () method does not result in multiple to create a service , but will result in a call onStart () method multiple times.





<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
onBind will be returned to the client a IBind interface instance, IBind service allows a client callback methods, such as the status of running to get Service or other operations. This time the caller and the Service will be bound together, but onBind only once, not repeatedly binding.
In the Service open and close every process, only onStart can be called multiple times (through multiple startService calls), other onCreate, onBind, onUnbind, onDestory in a life cycle can only be called once.

Reply:
The difference between the very detailed! Taught!
Use startService () method to enable the service, not related between the caller and the service, even if the caller exits, the service is still running. Use bindService () method to enable the service, the caller and the service is bound together, the caller once quit the service will terminate, great "while not seeking students must also die" features.

Reply:
onBind will be returned to the client a IBind interface instance, IBind service allows a client callback methods, such as the status of running to get Service or other operations.

What does this mean it. . Not clear? ?
Reply:
reference to the third floor passer_ming reply:
onBind will be returned to the client a IBind interface instance, IBind method allows the client callback services, such as running to get Service or other operating state.

What does this mean it. . Not clear? ?

"Due to the use of Android in the Service's approach to binding onBind service returns an object Ibinder operate, and we want to get the contents of a specific Service approach, we need to return to a specific object Ibinder Service object to operate, so that Specific Service object must first realize Binder object, like this, then we can use the method of Service bindService bind Binder object after obtaining access to specific Service object, then get Service method so. "
http://www.cnblogs.com/onlylittlegod/archive/2011/05/15/2046652.html
Reply:
startService and the caller is not a process which, bindService and the caller in one process
Reply:
Binding can only bind once, walking only once onBind (), start can start many times, walking many times onStartCommand (). The landlord here this analogy is inappropriate.

No comments:

Post a Comment