From 828cc272ee5235f868104b009349cc7e835e144f Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Sat, 12 Sep 2015 20:25:20 +1000 Subject: [PATCH] Only start Bluetooth in UI thread, WiFi needs background. While we're at it, use `Thread`s rather than `AsyncTask`s because they are more concise. Not 100% sure, but I think `AsyncTask`s need to wait for the UI event loop to get to them in order kick off. --- .../fdroid/localrepo/type/BluetoothSwap.java | 8 ++++++ .../fdroid/localrepo/type/SwapType.java | 27 ++++++++----------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/type/BluetoothSwap.java b/F-Droid/src/org/fdroid/fdroid/localrepo/type/BluetoothSwap.java index 8310e41ea..57563250a 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/type/BluetoothSwap.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/type/BluetoothSwap.java @@ -127,6 +127,14 @@ public class BluetoothSwap extends SwapType { } } + /** + * Don't try to start BT in the background. you can only start/stop a BT server once, else new connections don't work. + */ + @Override + public void stopInBackground() { + stop(); + } + @Override public void stop() { if (server != null && server.isAlive()) { 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 e3a7f6a33..47ad2c55f 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/type/SwapType.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/type/SwapType.java @@ -72,15 +72,12 @@ public abstract class SwapType { } public void startInBackground() { - start(); - /** - new AsyncTask() { + new Thread() { @Override - protected Void doInBackground(Void... params) { - start(); - return null; + public void run() { + SwapType.this.start(); } - }.execute();*/ + }.start(); } public void ensureRunning() { @@ -90,23 +87,21 @@ public abstract class SwapType { } public void ensureRunningInBackground() { - new AsyncTask() { + new Thread() { @Override - protected Void doInBackground(Void... params) { + public void run() { ensureRunning(); - return null; } - }.execute(); + }.start(); } public void stopInBackground() { - new AsyncTask() { + new Thread() { @Override - protected Void doInBackground(Void... params) { - stop(); - return null; + public void run() { + SwapType.this.stop(); } - }.execute(); + }.run(); } }