Skip to content

Commit

Permalink
Move android controller initialization to a background thread (zeroc-…
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone authored Dec 22, 2024
1 parent 0362b6d commit 91af574
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 91af574

Please sign in to comment.