How to execute a function every two seconds in Java on Android?

后端 未结 4 1552
无人共我
无人共我 2020-12-18 10:14

I\'m trying to execute a chunk of Java code in my Android program every two seconds. My code currently looks like this:

       LinearLayout.postDelayed(new R         


        
4条回答
  •  执笔经年
    2020-12-18 10:43

     new Timer().scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                // Enter your code which you want to execute every 2 second
            }
        }, 0, 2000);//put here time 1000 milliseconds = 1 second
    

提交回复
热议问题