How To Delay Seconds In Android?
I want to delay seconds and show Toast,I try to SystemClock.sleep But it only show last message('10s')... Toast.makeText(MainActivity.this,'1s', Toast.LENGTH_SHORT).show(); SystemC
Solution 1:
Try Handler
publicvoidshowToast(final String message, int timeInMilliSeconds, final Context context) {
Runnablerunnable=newRunnable() {
@Overridepublicvoidrun() {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
};
Handlerhandler=newHandler();
handler.postDelayed(runnable, timeInMilliSeconds);
}
Usage:
showToast("1s, 1000, this);
showToast("5s, 5000, this);
showToast("10s, 10000, this);
Post a Comment for "How To Delay Seconds In Android?"