From 6b449bb079a3156f6bd02a27eed6499d1c112ed8 Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 8 Feb 2019 14:11:35 -0800 Subject: [PATCH] null listener thread ref so will be restarted Once it died it stayed dead: bad. --- .../org/eehouse/android/xw4/BTService.java | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index 98f3f6d10..85d197955 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -417,7 +417,6 @@ public class BTService extends XWJIService { break; case START_BACKGROUND: - startListener(); noteLastUsed( this ); // prevent timer from killing immediately setTimeoutTimer(); break; @@ -540,7 +539,6 @@ public class BTService extends XWJIService { static void startYourself() { Log.d( TAG, "startYourself()" ); - // DbgUtils.assertOnUIThread(); synchronized ( s_listener ) { if ( s_listener[0] == null ) { s_listener[0] = new BTListenerThread(); @@ -552,19 +550,14 @@ public class BTService extends XWJIService { static void stopYourself( BTListenerThread self ) { Log.d( TAG, "stopYourself()" ); - BTListenerThread listener; + BTListenerThread curListener; synchronized ( s_listener ) { - listener = s_listener[0]; + curListener = s_listener[0]; s_listener[0] = null; } - if ( null != listener ) { - Assert.assertTrue( self == null || self == listener ); - listener.stopListening(); - try { - listener.join( 100 ); - } catch ( InterruptedException ie ) { - Log.ex( TAG, ie ); - } + if ( null != curListener ) { + Assert.assertTrue( self == null || self == curListener ); + curListener.stopListening(); } } @@ -608,6 +601,7 @@ public class BTService extends XWJIService { } closeServerSocket(); + stopYourself( this ); // need to clear the ref so can restart Log.d( TAG, "BTListenerThread.run() exiting" ); } // run() @@ -808,7 +802,8 @@ public class BTService extends XWJIService { @Override public void run() { - Log.d( TAG, "BTListenerThread.run() starting" ); + String className = getClass().getSimpleName(); + Log.d( TAG, "%s.run() starting", className ); for ( ; ; ) { BTQueueElem elem; // onTheWayOut: mFinishing can change while we're in poll() @@ -862,7 +857,7 @@ public class BTService extends XWJIService { } } } - Log.d( TAG, "BTListenerThread.run() exiting (owner was %s)", + Log.d( TAG, "%s.run() exiting (owner was %s)", className, BTService.this ); } // run