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?
-
Any special reason for not using Retrofit?Ricardo Costeira– Ricardo Costeira2018年12月12日 16:12:16 +00:00Commented 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!Derek– Derek2018年12月12日 22:58:40 +00:00Commented 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.Ricardo Costeira– Ricardo Costeira2018年12月12日 23:52:05 +00:00Commented Dec 12, 2018 at 23:52
1 Answer 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.
-
Your application is never sending benign junkStack Exchange Broke The Law– Stack Exchange Broke The Law2020年09月03日 11:32:33 +00:00Commented Sep 3, 2020 at 11:32
Explore related questions
See similar questions with these tags.