Skip to content

Instantly share code, notes, and snippets.

@rorist
Created October 22, 2010 12:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rorist/640454 to your computer and use it in GitHub Desktop.
Save rorist/640454 to your computer and use it in GitHub Desktop.
How to use Android's Handlers
import android.os.Handler;
private static final int MYACTION = 1;
private static final int DELAY = 1000; // ms
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MYACTION:
// do something
break;
}
}
};
private void sendMessage(){
Message msg = mHandler.obtainMessage(MYACTION);
mHandler.removeMessages(MYACTION);
mHandler.sendMessageDelayed(msg, DELAY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment