I have a Service that manages downloading tasks using using HttpURLConnection.
I use a custom isNetworkAvailable method before performing any HTTP request, but I'm wondering how to manage connection lost during the request.
Shall I call my isNetworkAvailable method in the while loop (which means lots of calls)? What's the standard way to manage connection lost with HttpURLConnection?
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
FileOutputStream outputStream = openFileOutput(filename, MODE_PRIVATE | MODE_APPEND);
BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
byte[] data = new byte[1024];
int x = 0;
while ((x = in.read(data, 0, 1024)) >= 0) {
outputStream.write(data, 0, x);
}