When you are on an activity, then use
runOnUiThread {
//code that runs in main
}
When you have activity context, mContext then use
mContext.runOnUiThread {
//code that runs in main
}
When you are in somewhere where no context available, then use
Handler(Looper.getMainLooper()).post {
//code that runs in main
}