How to get Executor for main thread on API level < 28
问题 On API level 28(Pie) a new method is introduced in the Context class to get Executor for the main thread getMainExecutor(). How to get this executor on API level below 28? 回答1: You can use (in activity for example): ContextCompat.getMainExecutor(this); https://developer.android.com/reference/androidx/core/content/ContextCompat.html#getMainExecutor(android.content.Context) 回答2: You can use code snippet from retrofit https://github.com/square/retrofit/blob/master/retrofit/src/main/java