display data after every 10 seconds in Android

后端 未结 6 1057
情深已故
情深已故 2020-11-28 07:20

I have to display some data after every 10 seconds. Can anyone tell me how to do that?

6条回答
  •  春和景丽
    2020-11-28 07:50

    Andrahu was on the right track with defining a handler. If you have a handler that calls your update functions you can simply delay the message sent to the handler for 10 seconds.

    In this way you don't need to start your own thread or something like that that will lead to strange errors, debugging and maintenance problems.

    Just call:

     Handler myHandler = new MyUpdateHandler(GUI to refresh); <- You need to define a own handler that simply calls a update function on your gui.
     myHandler.sendMessageDelayed(message, 10000);
    

    Now your handleMessage function will be called after 10 seconds. You could just send another message in your update function causing the whole cycle to run over and over

提交回复
热议问题