Try Handler
public void showToast(final String message, int timeInMilliSeconds, final Context context) {
Runnable runnable = new Runnable() {
@Override
public void run() {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
};
Handler handler = new Handler();
handler.postDelayed(runnable, timeInMilliSeconds);
}
Usage:
showToast("1s, 1000, this);
showToast("5s, 5000, this);
showToast("10s, 10000, this);
0
solved How to delay seconds in android?