Difference between service and intent service in android.
Service :
1. Service is using for complete the task in background.
2. It's a component of android.
3. All the component runs on main thread(ui thread). Hence Service also runs on main thread. It means that if we access the network content(like HttpUrlConnection) by using service,
then ANR(Application Not Responding) may occur. If we want to access network content, then we have to make separate thread in service.
4. The main thing about the service is that it runs always whether the given task is done or not.
5. For stopping the service,we have to stop this using stopService() method.
Intent Service :
1. Intent Service is a subclass of Service,which is used for complete the task in background.
2. It runs on a separate thread,means it doesn't block the main thread so that ANR error doesn't occur.
3. Intent service use worker thread for execute the task,means if we give it a lot of task to execute then it makes a queue for all the task and perform all the task one by one. If all the task is completed then it destroy itself. We don't need to call the stop function.
Comments
Post a Comment