Williams Williams - 3 years ago 72
Android Question

Service vs Thread in Android

I am looking for what service should be used in android applicaton.

Docs says

A Service is an application component that can perform long-running operations in the background and does not provide a user interface.

I have read this thread Application threads vs Service threads that saying same services are for running operation in background.

But here this can be done using
also. Any difference between them and where you should use them

Answer Source

A Service is meant to run your task independently of the Activity, it allows you to run any task in background. This run on the main UI thread so when you want to perform any network or heavy load operation then you have to use the Thread there.

Example : Suppose you want to take backup of your instant messages daily in the background then here you would use the Service.

Threads is for run your task in its own thread instead of main UI thread. You would use when you want to do some heavy network operation like sending bytes to the server continuously, and it is associated with the Android components. When your component destroy who started this then you should have stop it also.

Example : You are using the Thread in the Activity for some purpose, it is good practice to stop it when your activity destroy.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download