From ba95432e44395ce8e997abc61bcb75b02a9da632 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 5 Dec 2018 20:17:13 -0800 Subject: [PATCH] fix crash by not creating Handler until on UI thread Receiver is created and installed by a non-UI thread sometimes so can't create the Handler there. onReceive() is called on an ok thread however so create it there on demand. Fixes crash that showed when receiving relay messages in background. --- .../main/java/org/eehouse/android/xw4/NetStateCache.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java index 373c88ce2..198aa5c48 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NetStateCache.java @@ -181,8 +181,6 @@ public class NetStateCache { public PvtBroadcastReceiver() { - // DbgUtils.assertOnUIThread(); // firing - mHandler = new Handler(); mLastStateSent = s_netAvail; } @@ -191,6 +189,11 @@ public class NetStateCache { { DbgUtils.assertOnUIThread(); + if ( null == mHandler ) { + DbgUtils.assertOnUIThread(); + mHandler = new Handler(); + } + if ( intent.getAction(). equals( ConnectivityManager.CONNECTIVITY_ACTION)) {