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
  • 8,788
  • 2
  • 30
  • 50
abhishek
  • 775
  • 6
  • 17
  • 32

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,310
  • 6
  • 23
  • 38
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
  • 10,402
  • 4
  • 41
  • 68