TransWikia.com

Handling Networking on Android

Software Engineering Asked by Derek on January 31, 2021

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?

One Answer

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 by AardvarkBlue on January 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP