Android - running a method periodically using postDelayed() call

前端 未结 8 1387
一向
一向 2020-11-27 13:45

I have a situation in an Android app where I want to start a network activity (sending out some data) which should run every second. I achieve this as follows:

In th

8条回答
  •  难免孤独
    2020-11-27 14:23

    You can simplify the code like this.

    In Java:

    new Handler().postDelayed (() -> {
        //your code here
    }, 1000);
    

    In Kotlin:

    Handler().postDelayed({
       //your code here
    }, 1000)
    

提交回复
热议问题