Android - Call method from an Activity from a Thread
<p>I have the following snippet:</p>

<pre><code>public class SocketActivity extends Activity {
.
.
.
EditText textView;
Socket socket = new Socket(name,ip);
out = new PrintWriter(socket.getOutputStream());
out.flush();
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
.
.
.
}
</code></pre>

<p>Now, I have other lines to allow this activity to converse with a java server. But what I would like to do, is create a thread that constantly listens for a message from the server. Currently, it only listens for a response after I send a message. How would I set the textView from the thread? Is this the best way to do this? If not, where else should I do this?</p>

<p>======================</p>

<p>So, here is a more complete description of what I want to do, the textView is too primitive for what I want. So I have a <strong>MainActivity</strong> that creates a superclassed <strong>SurfaceView</strong> which has a superclassed <strong>Renderer</strong> that contains a <strong>Cube</strong> object with buffers, so it can be drawn. I also have a <strong>SocketActivity</strong> to connect to a server</p>

<p>What I want to do is wait for the server to send a packet of points to the client. Then, as each point is received it is put into the buffer. Then, once it completes, it waits again for the next packet. How should I use Asynctask be used to put a point to a buffer everytime I receive one. So to get a map of what's going on:</p>

<pre><code>public class MainActivity extends Activity {
    OpenGLSurfaceView view;
    .
    .
    .
}
public class OpenGLSurfaceView extends SurfaceView {
    OpenGLRenderer renderer;
    .
    .
    .
}
public class OpenGLRenderer extends Renderer {
    Cube cube;
    .
    .
    .
}
public class Cube{
private FloatBuffer vertexBuffer;
    .
    .
    .
}
public class SocketActivity extends Activity {
    Socket socket;
    BufferedReader in;
    PrintWriter out;
    .
    .
    .
}
</code></pre>

<p>Now where should the Asynctask be instantiated? Should I structure my program this way, or is there a better way? (For those that do not know, to put a primitive into a buffer you use <em>buffer.put(/*primitive*/)</em>, but this is trivial.)</p>
