In an android service I have created thread(s) for doing some background task.
I have a situation where a thread needs to post certain task on main thread\'s message
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
}