Very recently, both anko’s `runOnUiThread` , and m...
# android
n
Very recently, both anko’s
runOnUiThread
, and my own take on this (see below), have started to crash my app with this exception:
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
Copy code
fun executeOnMain(block: () -> Unit) {
    // Get a handler that can be used to post to the main thread
    val mainHandler = Handler(Looper.getMainLooper());

    <http://mainHandler.post|mainHandler.post>(Runnable(block));
}
Any idea? This is happening in the
onError
of RxJava (Retrofit with RxJava adapter), when handling a composite exception. Used to work fine for months. EDIT: It crashes on some devices (e.g. Samsung S7 with API 23), while it works fine on others (e.g. Nexus 5X emulator with API 23)…