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.
This commit is contained in:
Peter Serwylo 2015-09-12 20:25:20 +10:00
parent 4bb2a0e0d0
commit 828cc272ee
2 changed files with 19 additions and 16 deletions

View File

@ -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()) {

View File

@ -72,15 +72,12 @@ public abstract class SwapType {
}
public void startInBackground() {
start();
/**
new AsyncTask<Void, Void, Void>() {
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<Void, Void, Void>() {
new Thread() {
@Override
protected Void doInBackground(Void... params) {
public void run() {
ensureRunning();
return null;
}
}.execute();
}.start();
}
public void stopInBackground() {
new AsyncTask<Void, Void, Void>() {
new Thread() {
@Override
protected Void doInBackground(Void... params) {
stop();
return null;
public void run() {
SwapType.this.stop();
}
}.execute();
}.run();
}
}