title: How to call the handler from separate class in android?
body: <p>In my application, am try to set an time out function i not able to call the <strong>handler</strong>  method in separate class.</p>
  
  <p><strong>My Timeout Class</strong></p>
  
  <pre><code> public class Timeout_function {
  
  private Handler mHandler;
  Activity activity;
  
  public Timeout_function(Activity activity,Handler mHandler) {
      super();
      this.activity = activity;
      this.mHandler = mHandler;
  }
  
  Runnable myTask = new Runnable() {
      @Override
      public void run() {
          Toast.makeText(activity, "Test", 1000).show();
          mHandler.postDelayed(this, 1000);
      }
  };
  
  // just as an example, we'll start the task when the activity is started
  public void onStart() {
      mHandler.postDelayed(myTask, 1000);
  }
  
  // at some point in your program you will probably want the handler to stop
  // (in onStop is a good place)
  public void onStop() {
  
      mHandler.removeCallbacks(myTask);
  }
  }
  </code></pre>
  
  <p><strong>Main class</strong>
  In main class i call the method in this way,but it shows error in run time,</p>
  
  <pre><code>Timeout_function timeout = new Timeout_function(this, mHandler);
      timeout.onStart();
  </code></pre>
  
  <p>how to call the method in main class.can any one know please help me to solve this problem.</p>