3
I am currently using the volley
for web requests. But I’m finding this tool too slow.
I googled looking for alternatives, but all results I find are old, 2017, 2016 down.
About the org.apache.http
They say they are obsolete, among others also obsolete.
I found little information on the Gson
and from what I understand, I don’t think you even make web requests.
Some people talk about Retrofit
and Retrofit 2
, I haven’t tested yet.
But after all, now in 2018, what is the best way to do this? There is a way to use the native tools of android studio without installing any library and that is not obsolete?
Sorry I didn’t post any code, as I said I didn’t like Volley for being too slow. So I would really like a help on a more up-to-date tool. If possible some documentation or tutorial to use.
If I didn’t ask the question correctly please excuse me, I don’t know any other way to ask about it here. And for me here is being the only place with professionals who really understand what they’re talking about and who could help me.
I’m using the android studio 3.1.2, with minSdkVersion 15
and targetSdkVersion 27
Use https://developer.android.com/reference/java/net/HttpURLConnection, it is native.
– Valdeir Psr
I disagree with some things. 2017, 2016 results are not that old. If Volley is slow, it would be good to examine in search of the cause of the slowness that might not be Volley itself. As for the native library, it’s very low-level, I suggest in its place Okhttp.
– Piovezan
@Valdeirpsr Thanks, from what I checked it seems that in the update of android 6.0 they say to return and use the
HttpURLConnection
. I’ll try to see how does the POST and GET with it. Thank you.– Samanta Silva
@Piovezan I think Volley is too slow because of his cache system. For older phones and slower connection it takes a long time to return. Even if I start a new empty project only with it, the answer is very slow compared to other heavy applications I have installed on my mobile phone. About the
OkHttp
I’ll take a look, but because in your opinion the native is very low level??– Samanta Silva
@Samantasilva Compare a POST request on Okhttp and Httpurlconnection, the second has much more ceremony, both to assemble the connection and to read the received data.
– Piovezan
@Piovezan Ahh yes, that I imagined, for being a native tool must need a lot more lines of code. My fear is more for speed, performance, and that works on all devices, from the most current, to the oldest. About the codes for what I will do, I will use only once. So even q is much more work is no problem. Since q works well this great. But I like tbm the
OkHttp
that you suggested. I’m reading his documentation here. Thank you.– Samanta Silva
@Ssmantasilva I’m not sure I understand the cache question. If on slower phones it disrupts performance, maybe it was the case to try to disable the cache. See here: https://stackoverflow.com/questions/25333351/disable-volley-cache-management
– Piovezan
@Samantasilva "low level" = closer to the machine, less abstraction.
– bfavaretto
@Piovezan Ahh I didn’t know I could disable, but anyway I think I’ll use the
OkHttp
orHttpURLConnection
, I think for my use, these will be much lighter for the app. But if in the future I go back to using Volley now I know I can disable the cache, thanks again for the answer– Samanta Silva
@bfavaretto Thanks for the explanation
– Samanta Silva
Use for business projects
Retrofit
a few years ago, and before that I used toVolley
. I never had problems with either of the two, always attended very well.– LMaker
@Lmaker Even on older devices and slow connections you never had problems with them?? I was using Volley, and a simple request to return data in 2-line json was taking longer than receiving photos on Whatsapp, browsing facebook, or listing google photo files. I think the problem of Volley delay was because of the cache, above has a friend who taught me how to disable, but I find the native method much faster now and I’m enjoying it a lot.
– Samanta Silva
Comparison between all Libraries for HTTP request on android! Go to Retrofit =)
– Allef Sousa
@Samantasilva never had any problems. I used a Pixi 3 for tests in my old company and I never went slow like this. Sure it was no problem in the backend?
– LMaker
Take a look here: https://answall.com/a/173757/35406
– viana
@Lmaker Guess it wasn’t the backend, I switched to the
Okhttp
using the same links and the same request logic, and the speed difference was very large. Much faster than Volley. I did not test with Retrofit, because I read the documentation and saw that the retrofit works with Okhttp, so I did it straight without having to go through this library.– Samanta Silva
@Allefsousa Thanks for the nomination, I already solved with Okhttp, and it was much better than Volley. Adoreiii.
– Samanta Silva
@Viana I saw your link, on the comparison between Volley and retrofit I understood, but did not understand what the Ansytask is doing there. Because Ansytask has nothing to do with web requests, does it? As I understand it serves to run a thread in the background isn’t that right?? correct me if I’m wrong. I used Okhttp inside an Ansytask in my application and ameiii the result and speed.
– Samanta Silva