Câu hỏi phỏng vấn Android
Câu hỏi

What is the difference between Handler vs AsyncTask vs Thread ?

Câu trả lời

The main differences between Handler, AsyncTask, and Thread in Android are:

Thread:

  • Used for long-running or CPU-intensive tasks[1][2]
  • Runs on its own thread, manually managed[1]
  • Can't update UI directly, must use Handler[2]
  • Suitable for parallel tasks[1]

AsyncTask:

  • Used for short tasks that need to communicate with the UI thread[1][2]
  • Runs on a worker thread, can publish progress to UI thread[1][3]
  • Easier to use than raw Thread, handles threading and UI updates[2][3]
  • Limited to one execution at a time, can't run in a loop[1][3]
  • Not intended for long-running tasks, may cause issues[3]

Handler:

  • Used to schedule tasks to run at a later time or on a different thread[4]
  • Allows posting Runnable objects to a message queue[4]
  • Commonly used with Thread to update UI fr...
middle

middle

Gợi ý câu hỏi phỏng vấn

middle

What is the difference between onCreate() and onCreateView() lifecycle methods in Fragment ?

junior

What is View Group? How are they different from Views?

middle

What is the Support Library? Why was it introduced?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào