0

I have a service class which updates a static variable in my activity, I am having trouble trying to create code that will constantly run every 5 seconds to update say a textview.. using this variable.

How can I go about doing this?

1 Answers1

1

You can use a handler for running every 5 seconds See this sample code

    Handler h = new Handler();
int delay = 5000; //milliseconds

h.postDelayed(new Runnable(){
    public void run(){
        //do something
        h.postDelayed(this, delay);
    }
}, delay);

and in run method you can update your textview

Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84