How to call method outside class
<p>Is it possible to call method outside class, using an existing instance? I want to read data from sensor and try to send it through BT connection (already connected and sending other informations) but I cannot call write() method from "onSensorChange".</p>

<p>I am only capable to call write() and send message in "private class ConnectThread" (using connectedThread.write();).</p>

<p>Whole code works like a charm, I'm sending only most important parts of it to acquaint you with my problem.</p>

<p>Thanks in advance!</p>

<pre><code>public class MainActivity extends WearableActivity implements SensorEventListener{

BluetoothAdapter bluetoothAdapter;
String TEXT = "textToSend"; 
private SensorManager sensorManager;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);  
}

@Override
public void onSensorChanged(SensorEvent event) {     
   TEXT = "..something that I want to send..";

   ConnectedThread.currentThread.write(); //TOTAL nonsense, tried several things but 
//cannot call write(), how should I call this from existing thread?  
}


/* ___ Finding paired devices ___ */
private void pairedDevices() {       
    final ConnectThread connectThread = new ConnectThread(device);              
}


/* ___ Connecting to a Server. ___*/
private class ConnectThread extends Thread {

    private final BluetoothSocket mmSocket;
    private final BluetoothDevice mmDevice;
    ConnectedThread connectedThread;

    public void run() {
            mmSocket.connect();
            Log.d("Connected", "To Server");

            connectedThread = new ConnectedThread(mmSocket);
            connectedThread.start();
            connectedThread.write();
    }                 
}


/* Managing Connection */
private class ConnectedThread extends Thread {
    private final BluetoothSocket mmSocket;

    public ConnectedThread(BluetoothSocket socket) {

    private void write() { //How to acces this method from "public void onSensorChanged"?

        if (TEXT != null) {
            outputStream.println(TEXT);
            Log.d(TEXT, "Written to Server");
        }
    }
}
</code></pre>