My existing Android code uses AsyncTask to continuously poll data from a virtual COM port and dumps data to UI thread by overriding the onProgressUpdate() function. Something like the following:
open class ComActivity(deviceID:Int, listener: OnComRxUpdateUI) : AsyncTask<..., ..., ...>(){
...
override fun doInBackground(...) {
... //keep listening on serial port and transfer byte to buffer when available
}
override fun onProgressUpdate(...){
... //dump to ui
}
}
The above code works fine (except for some memory leak warnings here and there).
Every now and then, I see Coroutine being promoted for performing concurrent, and asynchronous operations, and I find compelled to try replacing AsyncTask with Coroutine. OTOH, I do not fully grasp the working of Coroutines as a substitute for AsyncTask. So my question is whether Coroutine is a viable replacement for my use case (continuous data polling and dumping on UI). Any good high-level (or pseudo) example
out there that demonstrate this use case are welcome.