AsyncTask's get() method: Is there any scenario where it is actually the best option?

后端 未结 9 533
臣服心动
臣服心动 2020-12-14 02:31

After answering this question, I got a doubt about the sense/usefulness of using the get() method of Android\'s AsyncTask class.

public final Result get ()
         


        
9条回答
  •  情歌与酒
    2020-12-14 03:01

    As the documentaion stands:

    "Waits if necessary for the computation to complete, and then retrieves its result."

    So it is mandatory that you avoid to call it on the UI Thread, otherwise you will get the NetworkOnMainThreadException. I would use it in a test enviroment which involves net operations or to wait another task to finish.

    EDIT: I was wrong about NetworkOnMainThreadException.

提交回复
热议问题