From 794a398cbfe73eb6917277c29b8652767b9226e1 Mon Sep 17 00:00:00 2001 From: yukimuon Date: Thu, 3 Dec 2020 01:17:18 -0500 Subject: [PATCH] disconnect bug fix --- .../main/java/com/cns/encom/MainActivity.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Android/app/src/main/java/com/cns/encom/MainActivity.java b/Android/app/src/main/java/com/cns/encom/MainActivity.java index fdf3770..65fb164 100644 --- a/Android/app/src/main/java/com/cns/encom/MainActivity.java +++ b/Android/app/src/main/java/com/cns/encom/MainActivity.java @@ -229,8 +229,6 @@ public void connect_onclick(View view){ TextView indicator_host = findViewById(R.id.Indicator_hostip); indicator_host.setText("Host: "+tarip); switchCam = true; - // TextView spd = findViewById(R.id.Indicator_speed); - connectionUp = true; if(mConnThread != null && mConnThread.isAlive()) logsWindows.append("You have already connected\n"); else{ @@ -240,17 +238,23 @@ public void connect_onclick(View view){ } public void disconnect_onclick(View view) { - connectionUp = false; - if(mConnThread != null){ - try{mConnThread.join();} - catch(InterruptedException e){mConnThread.interrupt();} + + if(connectionUp) { + if (mConnThread != null) { + try { + mConnThread.join(); + } catch (InterruptedException e) { + mConnThread.interrupt(); + } + } + TextView logsWindows = findViewById(R.id.textView); + logsWindows.append("You have disconnected\n"); + TextView indicator_host = findViewById(R.id.Indicator_hostip); + indicator_host.setText("Host: 0.0.0.0"); + mConnThread = null; + switchCam = false; + connectionUp = false; } - TextView logsWindows = findViewById(R.id.textView); - logsWindows.append("You have disconnected\n"); - TextView indicator_host = findViewById(R.id.Indicator_hostip); - indicator_host.setText("Host: 0.0.0.0"); - mConnThread = null; - switchCam = false; } public class connectionThread extends Thread{ @@ -288,6 +292,7 @@ public void run(){ if(rtspServerStarted) mainActivity.stopService(service); + connectionUp = true; mainActivity.startService(service); rtspServerStarted = true;