What is the equivalent to a JavaScript setInterval/setTimeout in Android/Java?

前端 未结 10 1148
遥遥无期
遥遥无期 2020-11-29 16:54

Can anyone tell me if an equivalent for setInterval/setTimeout exists for Android? Does anybody have any example about how to do it?

10条回答
  •  無奈伤痛
    2020-11-29 17:54

    The first answer is definitely the correct answer and is what I based this lambda version off of, which is much shorter in syntax. Since Runnable has only 1 override method "run()", we can use a lambda:

    this.m_someBoolFlag = false;
    new android.os.Handler().postDelayed(() -> this.m_someBoolFlag = true, 300);
    

提交回复
热议问题