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:
		
							parent
							
								
									4bb2a0e0d0
								
							
						
					
					
						commit
						828cc272ee
					
				@ -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()) {
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user