How to run send device command only when UART service is ready?
<p>I have a program which I would like to send command to a device via bluetooth once I receive result from my web service:</p>

<pre><code>@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
      case DEVICE_FOUND:
        if (resultCode == Activity.RESULT_OK &amp;&amp; data != null) {
            String deviceAddress = data.getStringExtra(BluetoothDevice.EXTRA_DEVICE);


            Log.d("nRFUART", "... onActivityResultdevice.address==" + deviceAddress);
            ((TextView) findViewById(R.id.txtState)).setText("Device found - configuration in process....");


            //activate a bluetooth connectivity to lock.

            if (mService.connect(deviceAddress)){
                Log.d("mService", " mService connected true");

            };

           //do a web service call for some values


            String rResult = "";


            WebServiceCallIO wsio = new WebServiceCallIO();
            try {

                rResult = wsio.execute(sURL + "ws/locki", deviceAddress,  Id, null, rResult).get();

                if (rResult == "") {
                    showMessage("Invalid request");
                }else{

                    btnTest.setEnabled(true);
                    instructDevice(rResult);
                }

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        break;
    default:
        Log.e(“DeviceActivity", "wrong request code");
        break;
}
</code></pre>

<p>}</p>

<p>The issue is, if I let the application run, I will receive an error when I come to the line "instructDevice(rResult);". If I run in debug mode, set a breakpoint at "btnTest.setEnabled(true);", the application run as it should.</p>

<p>I checked the connection to device via the line </p>

<pre><code>if (mService.connect(deviceAddress)){
            Log.d("mService", " mService connected true");

        };
</code></pre>

<p>and through the log, it shows the system log service is connected before I attempt to instruct the device.</p>

<p>Can someone throw some light to what is wrong with this piece of code?</p>

<p>Thanks!</p>