0

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

oshongo
  • 353
  • 1
  • 5
  • 8

5 Answers5

4

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

JB Nizet
  • 657,433
  • 87
  • 1,179
  • 1,226
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,265
  • 2
  • 15
  • 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,563
  • 1
  • 33
  • 68
1

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

Brian Agnew
  • 261,477
  • 36
  • 323
  • 432
1

For android I use CountDownTimer

Lojko
  • 173
  • 1
  • 13