title: how to sync time to android
body: <p>i have a url given to me to used for syncing the server time to my application, 
  Question is how to do that? anyone can explain to me what to do here thank i really appreciate it.</p>
  
  <p>here's the URL = <a href="http://server10.instaforex.com:2012/TimeService/TimeService.svc/CurrentTime" rel="nofollow">http://server10.instaforex.com:2012/TimeService/TimeService.svc/CurrentTime</a></p>
  
  <p>here is my mainactivity code.</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      Timer timeoutTimer;
      final Random myRandom = new Random();
      GenerateTask genTask = new GenerateTask();
      static String RAN_TEXT = "text";
  
      class GenerateTask extends TimerTask {
          boolean started = false;
          public void run() {
              if (started) {
                  System.out.println("generating");
                  final TextView textGenerateNumber = (TextView)findViewById(R.id.generatenumber);
                  RAN_TEXT = "";
  
                  for(int k=0;k&lt;7;k++){
                      RAN_TEXT += myRandom.nextInt(10) + " ";
                  }
                  runOnUiThread(new Runnable() {
  
                      @Override
                      public void run() {
                          textGenerateNumber.setText(RAN_TEXT);
                      }
                  });
              }
          }
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Button buttonGenerate = (Button)findViewById(R.id.generateme);
  
          buttonGenerate.setOnClickListener(new OnClickListener(){
  
              @Override
              public void onClick(View v) {
                  System.out.println("click");
                  if (!genTask.started) {
                      genTask.started=true;
                      timeoutTimer = new Timer();
                      timeoutTimer.scheduleAtFixedRate(genTask, 0, 30000);
                  } else {
                      genTask.started=false;
                      timeoutTimer.cancel();
                  }
              }
         });  
      }
  }
  </code></pre>