mcastiblanco
12/20/2017, 9:19 AMsuspend
function that calls a service, and then call that fun from onCreate
using Unconfined
so that the coroutine runes in main
. relevant parts of the code:
override fun onCreate(savedInstanceState: Bundle?) {
...
async(Unconfined) {
fetchNpr()
}
}
suspend fun fetchNpr() {
Log.d("TEST", "Hello from [${Thread.currentThread().name}] thread")
val factory = DocumentBuilderFactory.newInstance()
val builder = factory.newDocumentBuilder()
val xml = builder.parse("<https://www.npr.org/rss/rss.php?id=1001>")
Log.d("TEST", "Encoding ${xml.xmlEncoding}")
}
In the logs I see Hello from [main] thread
, and then nothing. The app keeps running as if nothing but the second log is never printed.
It doesn't seem like an expected behavior. I suppose the app should crash with NetworkOnMainThreadException
. Should I create a bug for this in github?