Skip to content

Instantly share code, notes, and snippets.

@illuzor

illuzor/async.kt Secret

Created September 14, 2018 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illuzor/5c2a916bfd02f54601dc7175ab64db18 to your computer and use it in GitHub Desktop.
Save illuzor/5c2a916bfd02f54601dc7175ab64db18 to your computer and use it in GitHub Desktop.
package com.illuzor.lesson.wallpapers.extensions
import android.os.Handler
import android.os.Looper
fun runInBackground(handler: () -> Unit) = Thread(Runnable(handler)).start()
fun runInMainThread(handler: () -> Unit) {
if (Looper.myLooper() == Looper.getMainLooper()) {
handler()
} else {
Handler(Looper.getMainLooper()).post(Runnable(handler))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment