From 26b35723d30b5d9e5b7fddfdacbcb475db2da0bb Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Fri, 26 Feb 2016 21:03:25 +0100 Subject: [PATCH] use AsyncTask for SwapType operations to run in background Thread runs at normal priority by default. AsyncTasks are integrated into Android for handling things running in the background while keeping the UI responsive. This reverts most of commit 828cc272ee5235f868104b009349cc7e835e144f. --- .../fdroid/localrepo/type/SwapType.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/type/SwapType.java b/F-Droid/src/org/fdroid/fdroid/localrepo/type/SwapType.java index 1a2ee1a78..8e45aafc8 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/type/SwapType.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/type/SwapType.java @@ -2,6 +2,7 @@ package org.fdroid.fdroid.localrepo.type; import android.content.Context; import android.content.Intent; +import android.os.AsyncTask; import android.support.annotation.NonNull; import android.support.v4.content.LocalBroadcastManager; @@ -70,12 +71,13 @@ public abstract class SwapType { } public void startInBackground() { - new Thread() { + new AsyncTask() { @Override - public void run() { - SwapType.this.start(); + protected Void doInBackground(Void... params) { + start(); + return null; } - }.start(); + }.execute(); } private void ensureRunning() { @@ -85,21 +87,23 @@ public abstract class SwapType { } public void ensureRunningInBackground() { - new Thread() { + new AsyncTask() { @Override - public void run() { + protected Void doInBackground(Void... params) { ensureRunning(); + return null; } - }.start(); + }.execute(); } public void stopInBackground() { - new Thread() { + new AsyncTask() { @Override - public void run() { - SwapType.this.stop(); + protected Void doInBackground(Void... params) { + stop(); + return null; } - }.start(); + }.execute(); } }