Wednesday, 11 August 2021

Application doesn't resume downloading after connection loss in Android emulator

I have the following code which just reads bytes from a connection:

CoroutineScope(Dispatchers.IO).launch {
    val conn = URL("https://mirror.yandex.ru/ubuntu-releases/20.04.2.0/ubuntu-20.04.2.0-desktop-amd64.iso").openConnection()
    val stream = conn.getInputStream()
    val byteBufferSize = 1024 * 100
    val buffer = ByteArray(byteBufferSize)
    do {
        val read = stream.read(buffer)
        println(read)
    } while (read != -1)
}.join()

When in the middle of reading I disconnect from the Internet, it stops reading and consequentially printing the number of bytes. Then I connect to the Internet it resumes downloading. I have the described behavior under JVM (non-Android).

When I try to run the same code in an Android emulator, disconnect (enable Airplane mode) and then connect to the Internet it doesn't resume downloading or maybe doesn't print to the console anymore.

What would cause such behavior under Android and how to fix it?



from Application doesn't resume downloading after connection loss in Android emulator

No comments:

Post a Comment