diff --git a/app/src/main/java/com/example/kingway/ptt/CallBackResolution.java b/app/src/main/java/com/example/kingway/ptt/CallBackResolution.java index e2d0187..7fef131 100644 --- a/app/src/main/java/com/example/kingway/ptt/CallBackResolution.java +++ b/app/src/main/java/com/example/kingway/ptt/CallBackResolution.java @@ -28,6 +28,7 @@ public class CallBackResolution { private static boolean loginState = false; private static String pttLoginStatus = "00"; // 00-未登录 01-登录中 02-已登录 private static String pttLoginId = ""; + private static ScheduledExecutorService keepAliveExecutor = null; public static String getPttLoginStatus() { return pttLoginStatus; @@ -543,13 +544,16 @@ public class CallBackResolution { if (tempTxt.contains("已登录")) { String showName = tempTxt.substring(3, tempTxt.length()); CallBackUtil.callBackLogin(true, showName); - ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); + if (keepAliveExecutor != null && !keepAliveExecutor.isShutdown()) { + keepAliveExecutor.shutdownNow(); + } + keepAliveExecutor = Executors.newSingleThreadScheduledExecutor(); Runnable task = () -> { Timber.tag(TAG).d( "callBackLogin send tcp and udp"); SendAtUtil.sendUDP(); SendAtUtil.sendTCP(); }; - executor.scheduleAtFixedRate(task, 0, 40, TimeUnit.SECONDS); + keepAliveExecutor.scheduleAtFixedRate(task, 0, 40, TimeUnit.SECONDS); } else if (tempTxt.contains("账号已更新")) { Timber.tag(TAG).w("TTS reports account updated: '%s'", tempTxt); } else if (tempTxt.contains("账号或密码错误")) {