diff --git a/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/netinfo/NetInfoModule.java b/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/netinfo/NetInfoModule.java index 650450230..a167d7513 100644 --- a/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/netinfo/NetInfoModule.java +++ b/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/nativemodules/netinfo/NetInfoModule.java @@ -30,6 +30,8 @@ import com.tencent.mtt.hippy.modules.javascriptmodules.EventDispatcher; import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleBase; import com.tencent.mtt.hippy.utils.LogUtils; +import java.util.concurrent.RejectedExecutionException; + @SuppressWarnings({"deprecation", "unused"}) @HippyNativeModule(name = "NetInfo") public class NetInfoModule extends HippyNativeModuleBase { @@ -155,24 +157,25 @@ public class NetInfoModule extends HippyNativeModuleBase { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { - mContext.getGlobalConfigs().getExecutorSupplierAdapter().getBackgroundTaskExecutor() - .execute(new Runnable() { - @Override - public void run() { - String currentConnectivity = getCurrentConnectionType(); - if (!currentConnectivity.equalsIgnoreCase(mCurrentConnectivity)) { - try { - mCurrentConnectivity = currentConnectivity; - HippyMap data = new HippyMap(); - data.pushString("network_info", mCurrentConnectivity); - mContext.getModuleManager().getJavaScriptModule(EventDispatcher.class) - .receiveNativeEvent(EVENT_NAME, data); - } catch (Throwable e) { - LogUtils.d("ConnectivityReceiver", "onReceive: " + e.getMessage()); - } - } + try { + mContext.getGlobalConfigs().getExecutorSupplierAdapter() + .getBackgroundTaskExecutor().execute(() -> { + String currentConnectivity = getCurrentConnectionType(); + if (!currentConnectivity.equalsIgnoreCase(mCurrentConnectivity)) { + try { + mCurrentConnectivity = currentConnectivity; + HippyMap data = new HippyMap(); + data.pushString("network_info", mCurrentConnectivity); + mContext.getModuleManager().getJavaScriptModule(EventDispatcher.class) + .receiveNativeEvent(EVENT_NAME, data); + } catch (Throwable e) { + LogUtils.d("NetInfoModule", "onReceive sendEvent: ", e); } - }); + } + }); + } catch (RejectedExecutionException e) { + LogUtils.d("NetInfoModule", "onReceive execute: ", e); + } } } }