nickk
01/19/2018, 11:39 AMrunOnUiThread
, 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()
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)…