0

While doing android development. There is really no clear way of doing network operations, Sending and receiving data.

Currently I am handing it using HttpsURLConnection and having streams to build a request and response.

But I've seen on android developers under Connectivity. Transmitting data using either Volley or Cronet.

I've created a test application using Volley and seems straight forward. However Volley requires the Context to run meaning it's now attached to the Android Framework. So sticking with MVVM it doesn't really fit.

I have also read about headless Fragments which is a Fragment that contains an inline AsyncTask class to handle networking

I could continue using my HttpsURLConnection DataOutputStream and InputStreamReader. Then MVVM and unit testing can still work. There just doesn't seem like standard way of doing this.

I am just looking to see if there is a more standard way of handling networking or not! Thanks!

  • Any special reason for not using Retrofit? – Ricardo Costeira Dec 12 '18 at 16:12
  • @rcosteira No specific reason. I actually haven't really heard of it before! I will have to check it out! – Derek Dec 12 '18 at 22:58
  • It’ll probably solve your problem :) no Android stuff needed. You can isolate it completely. Let me know how it goes. – Ricardo Costeira Dec 12 '18 at 23:52
0

I've been using URLConnection and building streams just like you, but it does seem discouraged by Google. For example, you need

         android:usesCleartextTraffic="true"

To use HTTPURLConnection now (as of 8.0 I believe), which is a hassle when your application is sending benign junk. That was a random break I didn't need.

I still think streams, in an ASyncTask, are the way to go. You can use a third party library like Volley but you never know when Android is going to break it. At least if they break streams like in the above example, you can typically fix it quickly. They're never going to completely drop streams and ASyncTask.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.