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?
            Asked
            
        
        
            Active
            
        
            Viewed 535 times
        
    0
            
            
        - 
                    1possible duplicate of [How to call a method after a delay](http://stackoverflow.com/questions/3072173/how-to-call-a-method-after-a-delay) – Dale Wilson Jun 25 '14 at 16:55
- 
                    Duplicate of this question: http://stackoverflow.com/questions/3072173/how-to-call-a-method-after-a-delay – Dale Wilson Jun 25 '14 at 16:56
- 
                    1Not a duplicate. This is android, that is iOS. – tbodt Jun 25 '14 at 23:29
2 Answers
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
 
    