title: How do i make Android app which do something every X second
body: <p>Hello i  wanna do apliacation which every 1 second call function or do something else.
  I have this code which is not working can you tell what is wrong?</p>
  
  <pre><code>public class App5_Thread extends Activity implements Runnable {    
          @Override
          public void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.main);
                  Thread thread = new Thread(this);    
                  thread.start();
          }
          @Override                    
          public void run() {                
                  TextView tv1 = (TextView) findViewById(R.id.tv);
                  showTime(tv1);                                                                
                  try {
                      Thread.sleep(1000);
                  }catch (Exception e) {
                      tv1.setText(e.toString());
                  }            
          } 
          public void showTime(TextView tv1 ){                
              String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
              Calendar cal = Calendar.getInstance();
              SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
              tv1.setText(sdf.format(cal.getTime())+" "+System.currentTimeMillis());                    
          }           
  </code></pre>
  
  <p>}</p>