diff --git a/app/src/main/java/foundation/e/drive/services/ObserverService.java b/app/src/main/java/foundation/e/drive/services/ObserverService.java index 99b718a3f49e5cf5808eff67651b6681a74c9063..7d6a2239f8e8bcc88645d9cc2984e7dbe6624187 100644 --- a/app/src/main/java/foundation/e/drive/services/ObserverService.java +++ b/app/src/main/java/foundation/e/drive/services/ObserverService.java @@ -20,6 +20,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.os.Handler; +import android.os.HandlerThread; import android.os.IBinder; import androidx.annotation.Nullable; @@ -72,12 +73,15 @@ public class ObserverService extends Service implements OnRemoteOperationListene private Account mAccount; private HashMap syncRequests; //integer is SyncedFileState id; Parcelable is the operation private SynchronizationServiceConnection synchronizationServiceConnection = new SynchronizationServiceConnection(); + private Handler handler; + private HandlerThread handlerThread; /* Lifecycle Methods */ @Override public void onDestroy(){ Timber.v("onDestroy()"); unbindService(synchronizationServiceConnection); + handlerThread.quitSafely(); super.onDestroy(); this.mSyncedFolders = null; } @@ -110,6 +114,10 @@ public class ObserverService extends Service implements OnRemoteOperationListene this.syncRequests = new HashMap<>(); initialFolderCounter = prefs.getInt(AppConstants.INITIALFOLDERS_NUMBER, 0); + + handlerThread = new HandlerThread("syncService_onResponse"); + handlerThread.start(); + handler = new Handler(handlerThread.getLooper()); begin(); return START_NOT_STICKY; } @@ -256,7 +264,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene try { final ListFileRemoteOperation loadOperation = new ListFileRemoteOperation(this.mSyncedFolders, this, this.initialFolderCounter); - loadOperation.execute(client, this, new Handler()); + loadOperation.execute(client, this, handler); } catch (IllegalArgumentException exception) { Timber.e(exception); } diff --git a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java index 7b5ceb864845bd14e2e17f4e6eef25e48bdb78dc..678e462e02ee95c936d0b723b98e0958a086910b 100644 --- a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java +++ b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java @@ -17,6 +17,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Binder; import android.os.Handler; +import android.os.HandlerThread; import android.os.IBinder; import androidx.annotation.Nullable; @@ -60,7 +61,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation private OwnCloudClient ocClient; private NextcloudClient ncClient; private Handler handler; - + private HandlerThread handlerThread; @Override public void onCreate() { super.onCreate(); @@ -87,11 +88,20 @@ public class SynchronizationService extends Service implements OnRemoteOperation threadPool = new Thread[workerAmount]; ocClient = DavClientProvider.getInstance().getClientInstance(account, getApplicationContext()); ncClient = DavClientProvider.getInstance().getNcClientInstance(account, getApplicationContext()); - handler = new Handler(); + + handlerThread = new HandlerThread("syncService_onResponse"); + handlerThread.start(); + handler = new Handler(handlerThread.getLooper()); return START_REDELIVER_INTENT; } + @Override + public void onDestroy() { + handlerThread.quitSafely(); + super.onDestroy(); + } + @Nullable @Override public IBinder onBind(Intent intent) {