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 it 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 a standard way of doing this.

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

Ola Ström
2091 gold badge2 silver badges6 bronze badges
asked Jun 18, 2018 at 17:16
3
  • Any special reason for not using Retrofit? Commented Dec 12, 2018 at 16:12
  • @rcosteira No specific reason. I actually haven't really heard of it before! I will have to check it out! Commented Dec 12, 2018 at 22:58
  • It’ll probably solve your problem :) no Android stuff needed. You can isolate it completely. Let me know how it goes. Commented Dec 12, 2018 at 23:52

1 Answer 1

1

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.

answered Nov 12, 2018 at 4:23
1
  • Your application is never sending benign junk Commented Sep 3, 2020 at 11:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.