title: how to show alert dialog from non-UI class ? getting error like -Can't create handler inside thread that has not called Looper.prepare()
body: <p>getting error like -java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()</p>
  
  <p>I am cerating application which has many activities . If user doesn't respond for a specific time (15 mins) then after 15 mins I wnat to show a dialog box which ask user "Are you still there ?"  and if user press "NO" application should close.
  I tried to do this with the help of 
  <a href="https://stackoverflow.com/questions/4075180/application-idle-time">Application idle time</a></p>
  
  <p>but I didn't created ControlApplication.java
  I directly called touch() from my each activity.
  and called Waiter class constructor from another java file which is global for my application.
  here is my code<br>
  Waiter.java</p>
  
  <pre><code>public class Waiter extends Thread
  {
  private static final String TAG=Waiter.class.getName();
  private long lastUsed;
  private long period;
  private boolean stop;
  private Context killContext;
  
  public Waiter( long period, Context context )
  {
      this.period=period;
      stop=false;
      killContext = context;
  }
  
  public void run()
  {
      long idle=0;
      this.touch();
      do
      {
          idle=System.currentTimeMillis()-lastUsed;
          Log.d(TAG, "Application is idle for --------------------------------------&gt;"+idle +" ms");
          Log.d(TAG, "lastUsed is  --------------------------------------&gt;"+lastUsed +" ms");
          Log.d(TAG, "currentTimeMillis is  --------------------------------------&gt;"+System.currentTimeMillis() +" ms");
          try
          {
              Thread.sleep(5000); //check every 50 seconds
          }
          catch (InterruptedException e)
          {
              Log.d(TAG, "----------------Waiter interrupted!-----------------------------------");
          }
          if(idle &gt; period)
          {
              idle=0;
              Log.d(TAG, "----------------inside if-----------------------------------");
              AlertDialog.Builder killBuilder = new AlertDialog.Builder( killContext );                    
              killBuilder.setMessage("Are you still there ?")
                  .setCancelable(false)
                  .setPositiveButton("Yes",
                      new DialogInterface.OnClickListener()
                      {
                          public void onClick(DialogInterface dialog, int id)
                          {
                              dialog.cancel();
                          }
                      })
                      .setNegativeButton("No",
                          new DialogInterface.OnClickListener()
                      {
                          public void onClick(DialogInterface dialog, int id)
                          {
                              android.os.Process.killProcess(
                                  android.os.Process.myPid() );
                          }
                      });
              Log.d(TAG, "----------------inside if killBuilder.create();;-----------------------------------");
              AlertDialog alert = killBuilder.create();
               Log.d(TAG, "----------------inside if alert.show();-----------------------------------");
              alert.show();
          }
      }
      while(!stop);
      Log.d(TAG, "--------------------------------Finishing Waiter thread-----------------------------");
  }
  
  public synchronized void touch()
  {
      lastUsed=System.currentTimeMillis();
  }
  
  public synchronized void forceInterrupt()
  {
      this.interrupt();
  }
  
  public synchronized void setPeriod(long period)
  {
      this.period=period;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>but  at alert.show(); I am getting above error. please help.</p>