title: How to loop or execute a function every 5 seconds on Android
body: <p>How can I loop that time() function on the onCreate every 5 seconds.. help me I'm a newbie in Android =) ... I want to execute time() function in onCreate every 5 seconds.</p>
  
  <pre><code> public void onCreate(Bundle savedInstanceState) {
   time(); //&lt;-- How can i execute this every 5 seconds.
   }
  
   private void time() {
  new Handler().postDelayed(new Runnable() {
  
      @Override
      public void run() {
              int success;
           gps = new GPSTracker(AdminMenu.this);
          if(gps.canGetLocation()){
              tmplat=latitude;
              tmplong=longitude;  
             // new InsertUser1().execute();      
          }
  
          else{
          gps.showSettingsAlert();
          }
  
          try {
              Thread.sleep(5000);
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          System.out.println("LATTTTT" + tmplat);
          System.out.println("LONGGGGGGGG" + tmplong);
      } 
  
  }, 5000); // 5 sec
  
   } 
  </code></pre>
  
  <p>Any help would be appreciated...</p>