Oct 21, 2021
The switchMap() operator runs the LiveData creation block on the main thread, yes. But you can use it to enqueue an operation on a backgroud thread, and from that thread publish the value asynchronously to the returned LiveData instance using postValue().
Example:
liveData.switchMap { source ->
val result = MutableLiveData()
val runnable = Runnable {
// some background work
result.postValue(data)
}
backgroundExecutor.execute(runnable)
result
}