0

I want to trigger a method 200ms after the onTouchUp event in android is called. I don't want to stop the current thread and I want to access the global variables in the method. I am also getting accelerometer data continuously so I don't want to stop or delay that. How do I do this?

Dale Wilson
  • 9,166
  • 3
  • 34
  • 52
abhishek
  • 817
  • 6
  • 19
  • 33

2 Answers2

2

You could use a delay on a handler.

new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
               methodToExecute(); 
            }
        }, 220)
Andre Perkins
  • 7,640
  • 6
  • 25
  • 39
1

Use something to run a Runnable after a specified delay, such as ScheduledExecutorService.

Runnable r = /* your runnable task */;
ScheduledExecutorService exec = /* your instance */;
exec.schedule(r, 200, TimeUnit.MILLISECONDS);
Rogue
  • 11,105
  • 5
  • 45
  • 71