android - AsyncTask return value -


In an example, I need to return my thread to a true or false value for my main thread.

Is there a way to get this return value from an asyncTask executed function?

When I do the following:

  Toast. Make text (Find out "test:" + location update. Exempt (location), toast. LNNHHLLG). Show ();  

I think what I want is a way to stop the main thread until the second thread is completed. The second thread calls a function in the main thread, which sets my return value. So when the second thread is complete, the main thread can unpause and access the return value set by another thread If this argument is sound, please provide suggestions ... thanks!

You can use the AsyncTask method for this. To complete the computation, if it is necessary, it waits for it, and then gets its results:

  Toast. MakeText ("Locate.This," test: "+ locationUpdate.execute (location) .get (), Toast.LENGTH_LONG) .show ();   

But be sure to not block the main thread for a long period, because it will boost unresponsive UI.

UPDATE
I remember the point about that async web about download / upload about the question. The web / network operation should be treated as a long time and thus use "stop UI threads and wait until the end of the download" from this perspective is always incorrect Use the normal result publishing process (Eg: AsyncTask.onPostExecute , libraries such as service + dispatch, volley, robospace, datadder etc.)

Comments