This is within a base class of a library, where several other classes inherit this one.
This seems like the simplest way of just getting some data, for now without timeout/errorhandling. This is supposed to get some data that will most ofthe time be converted to a small JSONObject.
Do you think I should put everything inside the try
and use val
? Any other suggestions? I'm basically just learning networking with android, only did it in C#.NET before.
protected fun sendGetRequest(url: URL): String {
var urlConnection: HttpsURLConnection? = null
var reader: InputStreamReader? = null
var responseData = ""
try {
urlConnection = url.openConnection() as HttpsURLConnection
reader = InputStreamReader(urlConnection.inputStream)
responseData = reader.readText()
}catch (e: Exception){
this.messageHandler.handleMessage(e.message!!)
}finally {
reader?.close()
urlConnection?.disconnect()
}
return responseData
}
this.messageHandler
do? \$\endgroup\$