title: Accessing method in MainActivity from Thread-Object
body: <p>in my Android App, I have a MainActivity Class, which starts a Thread. This Thread does Stuff and displays it on the screen. (This part is working)</p>
  
  <p><strong>From the Thread</strong> I want to access a method that is in the MainActivity-Class. But it does not work... "Cannot resolve method"</p>
  
  <p>Here is my Code...</p>
  
  <p><strong>The Thread-Object:</strong></p>
  
  <pre><code>public class SensorProcessor implements Runnable {
  
      protected Context mContext;
      protected Activity mActivity;
  
      private volatile boolean running = true;
      //Tag for Logging
      private final String LOG_TAG = SensorProcessor.class.getSimpleName();
  
      public SensorProcessor(Context mContext, Activity mActivity){
          this.mContext = mContext;
          this.mActivity = mActivity;
      }
  
  
      public void run() {
  
              while (running){
  
                  try {                    
  
                      final String raw = getSensorValue();
                      mActivity.runOnUiThread(new Runnable() {
                          public void run() {
                              //WORKS
                              final TextView textfield_sensor_value;
                              textfield_sensor_value = (TextView) mActivity.findViewById(R.id.text_sensor);
                              textfield_sensor_value.setText("Sensor Value: " + raw);
                              Log.v(LOG_TAG, raw);
  
  
                              //DOES NOT WORK, WHY?
                              mActivity.myMethod(); //Cannot resolve method
                          }
                      });
  
  
  
                      Thread.sleep(100);
                  } catch (InterruptedException e) {
                      //When an interrupt is called, we set running to false, so the thread can exit nicely
                      running = false;
                  }
              }
  
              Log.v(LOG_TAG, "Sensor Thread finished");
  
      }
  }
  </code></pre>
  
  <p><strong>The MainActivity Class, which is calling the Thread:</strong></p>
  
  <pre><code>public class MainActivity extends Activity implements OnClickListener, OnInitListener {
  
  
      public void myMethod(){
          //Do stuff...
      }
  
      //Start the Thread, when the button is clicked
      public void onClick(View v) {
          if (v.getId() == R.id.button_start) {
              runnable = new SensorProcessor(this.getApplicationContext(),this);
              thread = new Thread(runnable);
              thread.start();
          }
      }
  }
  </code></pre>
  
  <p>Why does it not work, with the mActivity.runOnUiThread(new Runnable() - Approach, and how is this done correctly?</p>
  
  <p>Best regards</p>