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