-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First call is blocking thread although enqueue is used #2502
Comments
Unclear what it’s doing without more information. There’s almost nothing that happens in |
Hi Jesse, in the meantime I managed to trace the problem down to Moshi which I used as a json parser. I replaced it with Gson and everything works fine. The first call still takes a bit longer, but it's only around 150ms. Should I close the issue here and open another in the Moshi repo? What additional information can I provide? |
Slow moshi is unexpected. Please open an issue there and the kind Moshi maintainers would be happy to help. |
Good day I still get |
Just a note for people with the same issue: I can confirm it was due to a slow initialization when using Moshi. Switched to Gson and the issue went away. |
I am using Retrofit 2 in an Android Application written in Kotlin for calling an API.
My call looks as follows:
The geocodingApi is initialised in the constructor of my class as follows:
The initialisation of the API is fast. The problem is, that the first call takes between 1.5 and 2 seconds blocking the UI Thread. All subsequent calls return directly and invoke the callback some time later when the call is finished. The logs look like this:
Wrapping all calls in a separate thread would be possible and produces the expected result (no UI-blocking), but according to the documentation calling
call.enqueue
should execute the result in the background by itself, and it works for all but the first call.Am I doing anything wrong? I am using Retrofit 2.3.0 and OkHttp 3.8.1.
Thanks in advance!
The text was updated successfully, but these errors were encountered: