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

What is the difference between AsyncTask and Thread/Runnable ?

Câu trả lời

The main differences between AsyncTask and Thread/Runnable in Android are:

  1. Threading model: AsyncTask runs on a separate worker thread by default, while Thread/Runnable requires manual thread management[1][2][4].

  2. UI interaction: AsyncTask allows publishing progress updates and delivering results to the UI thread, while Thread/Runnable requires manual UI thread access using methods like View.post(Runnable)[1][4][5].

  3. Lifecycle handling: AsyncTask handles configuration changes like screen rotations automatically, while Thread/Runnable requires manual lifecycle management[1][2].

  4. Execution: AsyncTask can only be executed once, while Thread/Runnable can be reused[2][4].

  5. Limitations: AsyncTask is designed for short-running tasks (a few seconds at most), while Thread/Runnable is suitable for longer-r...

middle

middle

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

expert

What is the onTrimMemory method?

senior

What is the difference between ArrayMap vs HashMap ?

middle

When to use Fragment s vs Activitie s?

Bình luận

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

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