From d917ac5e73fafba3fa63d13bdd17cfc3575da2e1 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Mon, 24 Dec 2018 09:51:25 +0100 Subject: [PATCH] Binder failed - cannot create handler inside thread that has not called looper.prepare (fixes #149) (#150) Fix Binder failed - cannot create handler inside thread that has not called looper.prepare (fixes #149) --- app/build.gradle | 4 ++-- .../service/RunConditionMonitor.java | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f4a1e1f5..33e446bd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,8 +37,8 @@ android { applicationId "com.github.catfriend1.syncthingandroid" minSdkVersion 16 targetSdkVersion 26 - versionCode 4182 - versionName "0.14.54.3" + versionCode 4183 + versionName "0.14.54.4" testApplicationId 'com.github.catfriend1.syncthingandroid.test' testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' playAccountConfig = playAccountConfigs.defaultAccountConfig diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java b/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java index cf9883df..fa209f30 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/RunConditionMonitor.java @@ -15,6 +15,8 @@ import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.BatteryManager; import android.os.Build; +import android.os.Handler; +import android.os.Looper; import android.os.PowerManager; import android.support.annotation.Nullable; import android.support.v4.content.LocalBroadcastManager; @@ -49,7 +51,17 @@ public class RunConditionMonitor { private final SyncStatusObserver mSyncStatusObserver = new SyncStatusObserver() { @Override public void onStatusChanged(int which) { - updateShouldRunDecision(); + /** + * We need a Looper here, see issue https://github.com/Catfriend1/syncthing-android/issues/149 + */ + Handler mainLooper = new Handler(Looper.getMainLooper()); + Runnable updateShouldRunDecisionRunnable = new Runnable() { + @Override + public void run() { + updateShouldRunDecision(); + } + }; + mainLooper.post(updateShouldRunDecisionRunnable); } };