how to use postDelayed() correctly in android studio?

后端 未结 3 1768
离开以前
离开以前 2020-11-29 06:41

I have a countDownTimer and if the user does not hit the gameButton within the 12th second I want the gameOver method called. problem I either get game function called insta

3条回答
  •  醉梦人生
    2020-11-29 07:06

    Below is the code that I use which works same as the accepted answer but is quite simple to write and understand.

    final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //Write whatever to want to do after delay specified (1 sec)
                        Log.d("Handler", "Running Handler");
                    }
                }, 1000);
    

提交回复
热议问题