Service is one of core component of android application. Every one knows service is very important part. we use it but sometimes we do not know exact power and depth of service, today i am going to discuss it in details.
After this article we will also let you know difference between Thread and Service, and how to perform real time task in service
In the end you will also get source code.
Service -A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.
Difference between a Thread , service and asynchronous task
1) Service is like an Activity but has no interface. Probably if you want to fetch the weather for example you won't create a blank activity for it, for this you will use a Service.
2) A Thread is a Thread, probably you already know it from other part. You need to know that you cannot update UI from a Thread. You need to use a Handler for this, but read further.
3) An AsyncTask is an intelligent Thread that is advised to be used. Intelligent as it can help with it's methods, and there are two methods that run on UI thread, which is good to update UI components
Other one difference between service and thread is that thread is not intelligent enough to recognize that is it already running or not? Every time you create a new object of thread and start again it will create a new instance and a new thread start running.
But if service is already running and you start again it will not created again.So that is very important difference
After this article we will also let you know difference between Thread and Service, and how to perform real time task in service
In the end you will also get source code.
Service -A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.
Difference between a Thread , service and asynchronous task
1) Service is like an Activity but has no interface. Probably if you want to fetch the weather for example you won't create a blank activity for it, for this you will use a Service.
2) A Thread is a Thread, probably you already know it from other part. You need to know that you cannot update UI from a Thread. You need to use a Handler for this, but read further.
3) An AsyncTask is an intelligent Thread that is advised to be used. Intelligent as it can help with it's methods, and there are two methods that run on UI thread, which is good to update UI components
But if service is already running and you start again it will not created again.So that is very important difference