From 476dc36eee17e53399d402b8b656e6b9c1818cd7 Mon Sep 17 00:00:00 2001 From: teamclouday Date: Sun, 29 Nov 2020 15:48:19 -0500 Subject: [PATCH] UI thread bug fix --- .../main/java/com/cns/encom/MainActivity.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 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 dfa2ca7..fdf3770 100644 --- a/Android/app/src/main/java/com/cns/encom/MainActivity.java +++ b/Android/app/src/main/java/com/cns/encom/MainActivity.java @@ -296,10 +296,10 @@ public void run(){ public void run() { TextView logsWindows = findViewById(R.id.textView); logsWindows.append("RTSP Server started\n"); + CheckBox cameraCheckbox = findViewById(R.id.checkBox); + cameraCheckbox.setChecked(true); } }); - CheckBox cameraCheckbox = findViewById(R.id.checkBox); - cameraCheckbox.setChecked(true); DataOutputStream out; try{ @@ -340,10 +340,15 @@ public void run() { catch(InterruptedException e){break;} } - mSurfaceHolder.setFormat(PixelFormat.TRANSPARENT); - mSurfaceHolder.setFormat(PixelFormat.OPAQUE); - cameraCheckbox = findViewById(R.id.checkBox); - cameraCheckbox.setChecked(false); + runOnUiThread(new Runnable() { + @Override + public void run() { + mSurfaceHolder.setFormat(PixelFormat.TRANSPARENT); + mSurfaceHolder.setFormat(PixelFormat.OPAQUE); + CheckBox cameraCheckbox = findViewById(R.id.checkBox); + cameraCheckbox.setChecked(false); + } + }); } int getRandomNumber(int min, int max){