The three methods are designed to be different.
Service: For actions that run continuously in the background for long periods of time, such as: Play music, view network data. Note that in the development documentation, the service itself is in the UI thread, so the desired action should be to create a new thread to complete the work.
Asynctask: Used primarily to prevent a one-time/short action blocking the UI thread. For example: Click button to get the network data, here asynctask more appropriate. Because the action is finished when the data is received. The service can also be used to complete the work, but then the service is closed, inefficient.
Thread: This is the usual meaning of threading, note that the UI cannot be updated in threads. Because the UI framework itself is non-thread safe. But Android provides the following ways to update the UI.
Activity.runOnUiThread(Runnable)
View.post(Runnable)
View.postDelayed(Runnable, long)
eg
Public voidOnClick(ViewV) {
New Thread(New Runnable() {
Public voidRun() {
Final BitmapBitmap=Loadimagefromnetwork("Http://example.com/image.png");
Mimageview.Post(New Runnable() {
Public void Run () {
Mimageview. Setimagebitmapbitmap }
}
start ();
}
See official documentation: http://developer.android.com/guide/components/processes-and-threads.html
/span>
Android Service vs Asynctask vs Thread