How to fetch data over network
Making a network request in Android is very cumbersome unless you use any third-party library. For example, let's take a look at how network requests in Android used to be:
try { URL url = new URL("<api call>"); urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.connect(); InputStream inputStream = urlConnection.getInputStream(); StringBuffer buffer = new StringBuffer(); if (inputStream == null) { // Nothing to do. return null; } reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { buffer.append(line + "\n"); } if (buffer.length() == 0) { return null; } result = buffer.toString(); } catch (IOException e) { Log.e("Request", "Error ", e); return null; } finally{ if (urlConnection != null) { urlConnection.disconnect...