From 8ea5f4e30803bd5cd58e022cbad5d6955ce0a7a0 Mon Sep 17 00:00:00 2001 From: johnny Date: Wed, 8 Sep 2021 00:44:23 -0700 Subject: [PATCH] Invoke error display on main thread to avoid crashing Failing to run the view change on the main thread may cause a CalledFromWrongThread exception as the view may not have been created from a thread in the IO pool. --- .../integration/MobileAppIntegrationPresenterBase.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/homeassistant/companion/android/onboarding/integration/MobileAppIntegrationPresenterBase.kt b/app/src/main/java/io/homeassistant/companion/android/onboarding/integration/MobileAppIntegrationPresenterBase.kt index 62cb9e21b31..49829402a32 100644 --- a/app/src/main/java/io/homeassistant/companion/android/onboarding/integration/MobileAppIntegrationPresenterBase.kt +++ b/app/src/main/java/io/homeassistant/companion/android/onboarding/integration/MobileAppIntegrationPresenterBase.kt @@ -47,7 +47,9 @@ open class MobileAppIntegrationPresenterBase constructor( integrationUseCase.registerDevice(deviceRegistration) } catch (e: Exception) { Log.e(TAG, "Unable to register with Home Assistant", e) - view.showError() + withContext(mainScope.coroutineContext) { + view.showError() + } return@launch } view.deviceRegistered()