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

What is an AsyncTask ?

Câu trả lời

What is an AsyncTask?

AsyncTask is a class provided by the Android framework that allows you to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers explicitly. It is designed to simplify the process of executing asynchronous tasks in Android applications.

Here are the key points about AsyncTask:

1. Asynchronous execution

AsyncTask enables proper and easy use of the UI thread. All the specific operations are done in a background thread, with only the results being published on the UI thread, minimizing the possibility of application freezing or crashing.

2. Simplified threading

AsyncTask abstracts away the complexity of setting up and managing threads. It provides a simple API for executing tasks asynchronously, without the need to deal with low-level threading details.

3. Lifecycle callbacks

AsyncTask provides several callback methods that are called at different stages of the task's lifecycle:

  • onPreExecute(): Called before the task is started, on the UI thread.
  • doInBackground(Params...): Runs on a background thread, where the actual work is perfor...
junior

junior

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

middle

What is the difference between a Bundle and an Intent ?

middle

What is Handler and what is it used for?

expert

What happens if the user navigates away or closes the app while I still have a reference to the Activity
the user just closed in my AsyncTask ?

Bình luận

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

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