From 2bac0d9504957d41eb5acd7eb9ff8b63be08833e Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Sat, 21 Mar 2015 21:42:33 +0100 Subject: [PATCH] Add FolderObservers in background thread (fixes #262). --- .../syncthing/SyncthingService.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java index bca10d8a..4689a61a 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java @@ -27,12 +27,9 @@ import com.nutomic.syncthingandroid.util.FolderObserver; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FilenameFilter; -import java.io.IOError; import java.io.IOException; -import java.io.InputStream; import java.lang.ref.WeakReference; import java.nio.channels.FileChannel; import java.util.HashSet; @@ -290,13 +287,18 @@ public class SyncthingService extends Service { @Override public void onApiAvailable() { onApiChange(); - for (RestApi.Folder r : mApi.getFolders()) { - try { - mObservers.add(new FolderObserver(mApi, r)); - } catch (FolderObserver.FolderNotExistingException e) { - Log.w(TAG, e.getMessage()); + new Thread(new Runnable() { + @Override + public void run() { + for (RestApi.Folder r : mApi.getFolders()) { + try { + mObservers.add(new FolderObserver(mApi, r)); + } catch (FolderObserver.FolderNotExistingException e) { + Log.w(TAG, "Failed to add observer for folder", e); + } + } } - } + }).start(); } }); registerOnWebGuiAvailableListener(mApi);