From 91af574db320d6b5ad935df0878f7de737ab7733 Mon Sep 17 00:00:00 2001 From: Jose Date: Sun, 22 Dec 2024 20:16:45 +0100 Subject: [PATCH] Move android controller initialization to a background thread (#3303) --- .../zeroc/testcontroller/ControllerActivity.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/java/test/android/controller/src/main/java/com/zeroc/testcontroller/ControllerActivity.java b/java/test/android/controller/src/main/java/com/zeroc/testcontroller/ControllerActivity.java index 71c787f7a84..825b8dae4ec 100644 --- a/java/test/android/controller/src/main/java/com/zeroc/testcontroller/ControllerActivity.java +++ b/java/test/android/controller/src/main/java/com/zeroc/testcontroller/ControllerActivity.java @@ -17,6 +17,8 @@ import android.widget.Toast; import java.util.LinkedList; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; public class ControllerActivity extends ListActivity { @@ -126,7 +128,18 @@ public void onNothingSelected(AdapterView arg0) } }); s.setSelection(0); - app.startController(this, bluetooth); + + // Start the controller in a background thread. Starting the controller creates the ObjectAdapter which makes + // IO calls. Android doesn't allow making IO calls from the main thread. + Executor executor = Executors.newSingleThreadExecutor(); + executor.submit(() -> { + try { + app.startController(this, bluetooth); + } catch (Exception e) { + e.printStackTrace(); + } + }); + executor.shutdown(); } public synchronized void println(String data)