M
M
Michael Kim2016-08-08 01:19:47
Java
Michael Kim, 2016-08-08 01:19:47

Where is the best place to interact with the view?

Where is it better to interact with the view: in the onPostExecute method in the AsyncTask descendant class, or with the get() method to receive the result of the doInBackground method in the activity and interact with the view already there?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2016-08-08
@Marox

It is better to try to use less AsyncTask, But:
1) AsyncTask - to perform asynchronous operations.
2) .get() makes it synchronous (doInBackground() is not executed on MainThread, but MainThread is waiting for execution to finish).
So the answer is, of course, in onPostExecute! Because otherwise the whole point of using AsyncTask is lost.

A
Artem Gapchenko, 2016-08-08
@artemgapchenko

In the method onPostExecute(). The method get()blocks the work of the thread that called this method (in your case it will be the ui thread if you want to interact with View) until doInBackground()it finishes its work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question