title: How to reset a variable after 3 seconds in Android?
body: <p>I am trying to create a <code>Service</code>. In this <code>Service</code> I ahve this variable:</p>
  <pre><code>String command=&quot;Go&quot;
  </code></pre>
  <p>I want to design a function that does this:</p>
  <blockquote>
  <p>Within 3 seconds, the command will return value &quot;Go&quot;</p>
  <p>If the time is bigger than 3 seconds, the command will be reset to &quot;&quot;.</p>
  </blockquote>
  <p>My current solution is using a <code>Thread</code>. Do you think it is a safe and good solution?</p>
  <pre><code>public String command;
  
  public String getValue(){
      command=&quot;GO&quot;;
      try {
          Thread.sleep(3000);
          command=&quot;&quot;;
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
      return command;
  }
  </code></pre>