title: How to add a timer/clock in android studio
body: <p>I am making an application, in which the user has to answer a series of questions under a certain amount of time, let's say 10seconds. I have gotten most of the code but the timer part. I want the current activity to end and either show a <code>Toast</code> or switch to some different activity.</p>
  <p>I tried <code>TimerTask</code> and <code>Timer</code> classes but they don't seem to work, no idea why.</p>
  <pre class="lang-java prettyprint-override"><code>     Timer t = new Timer();
       TimerTask timerTask = new TimerTask() {
           @Override
           public void run() {
               Toast.makeText(LevelOne.this, &quot;Times up!!!&quot;, Toast.LENGTH_SHORT).show();
               startNextLevel();
           }
       };
       t.schedule(timerTask,5000L );
  
       private void startNextLevel() {
           Intent nextLevel = new Intent(this, LevelTwo.class);
           startActivity(nextLevel);
       }
  </code></pre>