title: Android: Calling an activity from a Thread
body: <p>My problem is probably going to be simple and awkward at the same time, but I am a little stuck.</p>
  
  <p>I have a Main.java class, that extends Activity.</p>
  
  <p>Inside that class, I do the following:</p>
  
  <pre><code>ringerServer = new Thread(new RingerServer());
  ringerServer.start();
  </code></pre>
  
  <p>What I want to do is have the RingerServer thread running continously.</p>
  
  <p>Inside that thread, I listen for a TCP connection. If I get one, I start another class, which sends and receives UDP packet.</p>
  
  <pre><code>public class RingerServer implements Runnable {
  
      public static final int SERVERPORT = 4445; // Default port to connect to
  
      @Override
      public void run() {
          try {
              // Create a socket for handling incoming requests
              ServerSocket server = new ServerSocket(SERVERPORT);
  
              while (!VoIPCall.onCall) {
                  // Wait for an incoming connection
                  Socket clientSocket = server.accept();
  
                  // TODO: Display a message for the user to accept or decline
  
                  // For now, automatically accept the call
                  Intent myIntent = new Intent(null, VoIPCall.class);
                  // Put the IP as a parameter
                  myIntent.putExtra("inetAddress", clientSocket.getInetAddress());
                  startActivity(myIntent);
              }
  
          } catch (IOException e) {
              Log.e("TCP", "S: Error", e);
          }
      }
  }
  </code></pre>
  
  <p>My problem has to do with the lines:</p>
  
  <pre><code>Intent myIntent = new Intent(null, VoIPCall.class);
  myIntent.putExtra("inetAddress", clientSocket.getInetAddress());
  startActivity(myIntent);
  </code></pre>
  
  <p>Those lines would work fine inside an Activity but it doesn't to complain as it is a Thread, it doesn't know about the Activity class, because it doesn't extend it, but implements Runnable.</p>
  
  <p>I am not sure how I can make my program keep running the RingerServer but have the main thread go to VoIPCall class. Any ideas please?</p>
  
  <p>I really appreciate your help.</p>
  
  <p>Thank you very much,</p>
  
  <p>Jary</p>