It’s generally suggested to use Handler.post() in Android when need to do some jobs in different threads.
And when I want to do some jobs in the background, I was suggested to start a Service.
But I feel more convenient using new Thread (new Runnable(){...} ); as I used to.
But I am afraid that creating new threads by hand may behave differently in Android, such as maybe automatically stop when memory is low while using Service might not ?
Wishing a clear answer to help me out of this confusion. ^ ^
When performing certain jobs in android it is greatly suggested to use Handler because :
In Android one can only update views in its original thread, i.e., the thread in which they were created, otherwise the app may throw an exception saying
Handlers in Android bind with the thread in which they are created. Each Handler instance is associated with a single thread and that thread’s message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it — from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue. So Handlers are the safest to go around in Android.
While Services, Heres a piece of code from http://developer.android.com/reference/android/app/Service.html
What is a Service?
Most confusion about the Service class actually revolves around what it is not:
A Service is not a separate process. The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of.
A Service is not a thread. It is not a means itself to do work off of the main thread (to avoid Application Not Responding errors).
Thus a Service itself is actually very simple, providing two main features:
A facility for the application to tell the system about something it wants to be doing in the background (even when the user is not directly interacting with the application). This corresponds to calls to Context.startService(), which ask the system to schedule work for the service, to be run until the service or someone else explicitly stop it.
A facility for an application to expose some of its functionality to other applications. This corresponds to calls to Context.bindService(), which allows a long-standing connection to be made to the service in order to interact with it.
And lastly Threads,
threads are used to perform some heavy non-view functions, some heavy computation works like parsing, etc so that it does not block you UI and safely performs all the work …