Created
July 27, 2014 06:04
-
-
Save rajbharath/a30b7a20a6dbc74717be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. it is used for background proces such as downloading a file. | |
2. it does not need user interface | |
3. for writing a service we need to extend the base service class provided by android | |
it is two kind: | |
1. service started | |
2. service bound | |
lifeCycle: | |
start service : | |
onCreate -> onStartCommmand -> (service can be stopped by itself(stop(self)) or by client calling stop(service)) -> onDestroy | |
bound service: | |
onCreate -> onBind -> onUnBind()-> onDestory() | |
if asked more details: | |
1. startService method for service started type. this has no user interface. it started from any other app component then it runs on it same process. | |
2. if the service is doing os intensive work, it is better to do from another thread. | |
3. IntentService provides api for running the service is another | |
4. this kind of services used only in your application. | |
1. bindService is used for showing the background process status in the user interface and interacting with the background process | |
2. this should be passed a service connection | |
3. boundservice will take time to get bound with the process bcoz they can be accessed across applications. there will be a request queue maintained for all the application reqeusts. | |
4. that message q will dispatch the request one by one. | |
5. when the reqeust is dispatched and the service bound to the process, it will call onBind call back method in UI thread and it returns the binder. | |
6. binder will give the service instance and using that service instance we can call the public methods in the service. | |
7. once all the requests are dispatched from the queue and there is no more process in bound with the service then service will be destroyed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment