Retrofit: How to wait for response

前端 未结 2 1711
故里飘歌
故里飘歌 2021-02-05 16:48

I have AsyncTask and the doInBackground method inside which, I sending POST request using Retrofit. My code looks like:

    //method of AsyncTask
    protected B         


        
相关标签:
2条回答
  • 2021-02-05 17:15

    The Call class has an execute() method that will make your call synchronously.

    enqueue() is explicitly for making an asychronous call.

    0 讨论(0)
  • 2021-02-05 17:30

    "Retrofit sending request asynchronously" which as @Tanis.7x mentioned, enqueue() is doing the asynchronous, so what could be a reason to put in AsyncTask ? (async in async ?)

    You can simply put all retrofit code out from AsyncTask and onResponse is the callback that is waiting for your request call to be back, so you can do any UI update inside of this callback.

    0 讨论(0)
提交回复
热议问题