Whats the recommended approach for using
scope.launch {}
from MainScope? Generally, the task itself will run with the "correct" dispatcher, for example: loading something from a database is always executed using
withContext(<http://Dispatchers.IO|Dispatchers.IO>)
.
But to me it seems that I might as well specify something like
Dispatchers.Default
in the launch block, so that
all tasks are at least off-loaded from the main thread by default? As a real life scenario, I was just working on an issue where UI froze after the user had selected a file to import from; I had failed to realize that contentResolver.openInputStream(uri) was blocking rather than reading from the inputStream itself. If I had been using
Dispatchers.Default
, this wouldnt have been a problem. Now, instead I have to wrap each individual call like this (there arent many, but still) in a
withContext(Dispatchers.Default/IO)
.