These answers need to be updated to use more contemporary way to connect to servers on Internet and to process asynchronous tasks in general, e.g. you can find examples where Tasks are used in Google Drive API sample. The same should be used in this case. I'll use OP's original code to demonstrate this approach.
First, you'll need to define an off-main thread executor and you need to do it only once:
private val mExecutor: Executor = Executors.newSingleThreadExecutor()
Then process your logic in that executor, which will be running off main thread
Tasks.call (mExecutor, Callable<String> {
val url = URL(urlToRssFeed)
val factory = SAXParserFactory.newInstance()
val parser = factory.newSAXParser()
val xmlreader = parser.getXMLReader()
val theRSSHandler = RssHandler()
xmlreader.setContentHandler(theRSSHandler)
val is = InputSource(url.openStream())
xmlreader.parse(is)
theRSSHandler.getFeed()
// complete processing and return String or other object
// e.g. you could return Boolean indicating a success or failure
return@Callable someResult
}).continueWith{
// it.result here is what your asynchronous task has returned
processResult(it.result)
}
continueWith clause will be executed after your asynchronous task is completed and you will have an access to a value that has been returned by the task through it.result.