How to organize a method for a no-try bluetooth connection without lagging?
current method
BluetoothDevice device = btAdapter.getRemoteDevice(MacAddress); Log.d(LOG_TAG, "***Получили удаленный Device***" + device.getName()); try { btSocket = device.createRfcommSocketToServiceRecord(MY_UUID); Log.d(LOG_TAG, "...Создали сокет..."); } catch (IOException e) { MyError("Fatal Error", "В onResume() Не могу создать сокет: " + e.getMessage() + "."); } btAdapter.cancelDiscovery(); Log.d(LOG_TAG, "***Отменили поиск других устройств***"); Log.d(LOG_TAG, "***Соединяемся...***"); try { btSocket.connect(); statusOnliV.setText("ok"); try { new Handler().postDelayed(new Runnable() { @Override public void run() { MyThred.sendData("100"); } }, 1000); } catch (Exception e) { Log.d(LOG_TAG, "====Ошибка отправки===="); } Log.d(LOG_TAG, "***Соединение успешно установлено***"); } catch (IOException e) { try { btSocket.close(); } catch (IOException e2) { MyError("Fatal Error", "В onResume() не могу закрыть сокет" + e2.getMessage()+ "."); } /* Log.d(LOG_TAG, "***Переход к Error seratch***"); showToastMessage("Переход к Error seratch"); Intent intentErrorSertch = new Intent(Home.this, ErrorSertch.class); startActivity(intentErrorSertch); finish(); */ } MyThred = new ConnectedThred(btSocket); MyThred.start(); connected = true;