Question

I have read that a service is different from thread because it is not affected by the current activity. But threads are. But Looper is also same like a service which doesn't get affected by the current activity and they both run in background.

So what basically differs a service and a looper... ?

Please help me out. I am totally confused in these topics.

Was it helpful?

Solution

Looper is a class which is used to execute the Messages(Runnables) in a queue. Normal threads do not have any queue. For example, Simple threads do not have any queue. They are for one time execution and after the end of the code the thread will be stopped/killed and it will not able to run another Message(Runnable).

Usage If you wants to execute multiple messages(Runnables) then you should use the Looper class which is responsible for creating a queue in the thread. For example. If you are writing an application which downloads files from the internet then you can use Looper class to put all the files in the queue to be downloaded.

Service runs in a different process, Say in an application if it gets crashed or the process in which application was running gets killed then Async Task/looper will also be killed but not Service because service was running in a differnt process. Looper run in the same thread as of app unkike Service .Also Android Recommends to use Async task rather than Loopers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top