Created
October 22, 2010 12:30
-
-
Save rorist/640454 to your computer and use it in GitHub Desktop.
How to use Android's Handlers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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