title: How to use timer in Android
body: <p>In my application i have <strong>timer</strong> for some works.<br>
  When my application running after some time my application <strong>freeze</strong> and not work any View !
  <br>
  In this timer every <strong>500ms</strong> i <code>emit</code> <strong>socket.io</strong></p>
  
  <p>My Codes:</p>
  
  <pre><code>   AsyncTask.execute(new Runnable() {
          @Override
          public void run() {
              socketPingTimer.scheduleAtFixedRate(new TimerTask() {
                  @Override
                  public void run() {
                      if (isSendSocketPing) {
                          checkSocketPingTimer += startSocketPingTimer;
                          if (checkSocketPingTimer == sendSocketPingTimer) {
                              currentTimerForSocket = System.currentTimeMillis();
                              try {
                                  detailSocketUtils.getSendRTTforPing(currentTimerForSocket + "");
                              } catch (Exception e) {
                              }
                          }
                          //Show ping (from search)
                          Constants.currentActivity.runOnUiThread(new Runnable() {
                              @Override
                              public void run() {
                                  if (isShownPing) {
                                      detailToolbar_ping.setVisibility(View.VISIBLE);
                                      if (checkSocketPingTimer &gt; 500) {
                                          detailToolbar_ping.setText(checkSocketPingTimer + "");
                                          detailToolbar_ping.setTextColor(Color.RED);
  
                                      } else {
                                          detailToolbar_ping.setText(checkSocketPingTimer + "");
                                          detailToolbar_ping.setTextColor(Color.GREEN);
                                      }
                                  } else {
                                      detailToolbar_ping.setVisibility(View.GONE);
                                  }
                              }
                          });
                          socketPing = checkSocketPingTimer;
                      }
                  }
              }, 500, startSocketPingTimer);
          }
      });
  </code></pre>
  
  <p>How can i run this timers in another <code>thread</code> and <strong>not freeze</strong> my app ?</p>