|
|
|
@ -11,7 +11,7 @@ import kotlinx.coroutines.launch |
|
|
|
|
|
|
|
|
|
/** This main looper cache avoids synchronization overhead when accessed repeatedly. */ |
|
|
|
|
@JvmField |
|
|
|
|
val mainLooper: Looper = Looper.getMainLooper()!! |
|
|
|
|
val mainLooper: Looper = Looper.getMainLooper() |
|
|
|
|
|
|
|
|
|
@JvmField |
|
|
|
|
val mainThread: Thread = mainLooper.thread |
|
|
|
@ -22,15 +22,17 @@ val isMainThread: Boolean inline get() = mainThread === Thread.currentThread() |
|
|
|
|
internal val currentThread: Any? |
|
|
|
|
inline get() = Thread.currentThread() |
|
|
|
|
|
|
|
|
|
@JvmField |
|
|
|
|
val mainHandler: Handler = if (SDK_INT >= 28) Handler.createAsync(mainLooper) else try { |
|
|
|
|
val mainHandler: Handler by lazy { |
|
|
|
|
if (SDK_INT >= 28) Handler.createAsync(mainLooper) else try { |
|
|
|
|
Handler::class.java.getDeclaredConstructor( |
|
|
|
|
Looper::class.java, |
|
|
|
|
Handler.Callback::class.java, |
|
|
|
|
Boolean::class.javaPrimitiveType // async |
|
|
|
|
).newInstance(mainLooper, null, true) |
|
|
|
|
} catch (ignored: NoSuchMethodException) { |
|
|
|
|
Handler(mainLooper) // Hidden constructor absent. Fall back to non-async constructor. |
|
|
|
|
// Hidden constructor absent. Fall back to non-async constructor. |
|
|
|
|
Handler(mainLooper) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun runOnUI(function: () -> Unit) { |
|
|
|
|