How can I return value from onResponse of Retrofit v2

前端 未结 2 542
失恋的感觉
失恋的感觉 2020-12-15 01:23

I want to return a string value from my function. But I do not know how to handle it? I tried final one-array solution but it did not work out.

Here is my code:

2条回答
  •  太阳男子
    2020-12-15 01:44

    With retrofit2 is possible make synchronous call:

    Callback callback = BaseService.getInstance().getUniqueCourt(Session.getToken(),courtID)
    Response response = callback.execute();
    ...
    

    however, synchronous requests trigger app crashes on Android 4.0 or newer. You’ll run into the NetworkOnMainThreadException error.

    More information here.

提交回复
热议问题