Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java's equivalent of [self performSelector:foo afterDelay:2]

Tags:

java

android

i am developing an android app i need to go from one activity to another in that first i need to change the colors of button then a delay (so that the) and then call this same function(the one i am in rite now)

in objective-c it is done with [self performSelector:foo afterDelay:2]

so i need to the its java equivalent.

like image 228
giles ian Avatar asked Jan 31 '10 07:01

giles ian


1 Answers

For delayed actions in Android I'd recommend using the Android Handler class with its postDelayed() method.

Create a handler for your Activity as a member variable:

private Handler mHandler = new Handler(); 

And then add your delay action as follows:

mHandler.postDelayed(new Runnable() { 
        public void run() { 
            //Do you thing here
        } 
    },2000);
like image 97
Dave Webb Avatar answered Oct 21 '22 17:10

Dave Webb