I am trying to understand the Bluetooth example given in the Android
Developer docs and I am wondering about this issue:

The example shows a "ConnectedThread" class which extends the standard
Thread class.  There is a custom constructor and a run() method which
executes in the newly-created thread, managing the input stream.  But
this ConnectedThread class also exposes another method - write(byte[]
bytes), which is supposed to be called from the main UI thread.  But
doesn't the code in this methods actually execute in the main UI
thread?  If so, then why does write(byte[] bytes) look like this:

    /* Call this from the main Activity to send data to the remote
device */
    public void write(byte[] bytes) {
        try {
            mmOutStream.write(bytes);
        } catch (IOException e) { }
    }

and are told that mmOutStream.write() is a blocking call.  So why does
the official Bluetooth sample show the main UI calling a blocking
method, unless this code is somehow executed by the worker thread.
But I thought that only the code within the run() method is executed
in the worker thread.  Can someone clear up this confusion for me?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to