0

I would like to create a program that execute a method after 10 seconds, how to do it in java or android???

oshongo
  • 403
  • 1
  • 6
  • 8

5 Answers5

4

You could use a ScheduledExecutorService, and submit a Runnable or Callable which calls your method.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
3

Try this code,

  final Handler mTimerHandler = new Handler();
       final Handler threadHandler = new Handler();
       new Thread() {
               @Override
               public void run() {
                       threadHandler.postDelayed(new Runnable() {
                               public void run() {

                               }
                       }, 5000);
               }
       }.start();
MuraliGanesan
  • 3,233
  • 2
  • 16
  • 22
2

Look at TimerTask : A task that can be scheduled for one-time or repeated execution by a Timer.

Example: Schedule Periodic Tasks

Azodious
  • 13,752
  • 1
  • 36
  • 71
1

You should look at Timer and TimerTask. Here's a tutorial on this.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
1

For android I use CountDownTimer

Lojko
  • 173
  • 1
  • 13