0

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 Toast or switch to some different activity.

I tried TimerTask and Timer classes but they don't seem to work, no idea why.

     Timer t = new Timer();
     TimerTask timerTask = new TimerTask() {
         @Override
         public void run() {
             Toast.makeText(LevelOne.this, "Times up!!!", Toast.LENGTH_SHORT).show();
             startNextLevel();
         }
     };
     t.schedule(timerTask,5000L );

     private void startNextLevel() {
         Intent nextLevel = new Intent(this, LevelTwo.class);
         startActivity(nextLevel);
     }
Thecave3
  • 744
  • 12
  • 27
  • Does this answer your question? [How to set timer in android?](https://stackoverflow.com/questions/4597690/how-to-set-timer-in-android) – Thecave3 Apr 13 '22 at 19:40

0 Answers0