android add delay before calling function code example
Example 1: how to call a function after delay in kotlin android
// Android 10+ Handler() is depricated
// Import
import android.os.Handler;
import android.os.Looper
val handler = Handler(Looper.getMainLooper())
handler.postDelayed({
// do something after 1000ms
}, 1000)
Example 2: handler delay android
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 100ms
}
}, 100);
Example 3: handler delay android
Handler().postDelayed({
//Do something after 100ms
}, 100)