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.
This commit is contained in:
Eric House 2018-12-05 20:17:13 -08:00
parent 68ae9790b4
commit 051aeba57c

View file

@ -181,8 +181,6 @@ public class NetStateCache {
public PvtBroadcastReceiver() public PvtBroadcastReceiver()
{ {
// DbgUtils.assertOnUIThread(); // firing
mHandler = new Handler();
mLastStateSent = s_netAvail; mLastStateSent = s_netAvail;
} }
@ -191,6 +189,11 @@ public class NetStateCache {
{ {
DbgUtils.assertOnUIThread(); DbgUtils.assertOnUIThread();
if ( null == mHandler ) {
DbgUtils.assertOnUIThread();
mHandler = new Handler();
}
if ( intent.getAction(). if ( intent.getAction().
equals( ConnectivityManager.CONNECTIVITY_ACTION)) { equals( ConnectivityManager.CONNECTIVITY_ACTION)) {