1

In My application I want to check data after every second, using service. I have tried to use Timer but it doesn't allow me to use 'runOnUiThread' in service. In Activity Timer works fine.

or

Is there any other way to trace database at every seconds?

Nirav
  • 5,700
  • 4
  • 34
  • 44

2 Answers2

0

Use thread u can trace the data base every time

    try{
        thread=new Thread()
        {
            @Override
            public void run() {
                while(set) {
                    thread_Run();
                }
            }
        };

    }
    catch(Exception e)
    {
        Toast.makeText(this, "error", Toast.LENGTH_SHORT).show();
    }
kannappan
  • 2,250
  • 3
  • 25
  • 35
0

Implement a Runnable, that way you can use the runOnUiThread(runnable) functionality.

private Runnable mUpdateTimeTask = new Runnable() {
   public void run() {
      //do ui update
   }
};

Edit: try this: More efficient way of updating UI from Service than intents?

Edit2: http://developer.android.com/resources/articles/timed-ui-updates.html

Community
  • 1
  • 1
Mark Mooibroek
  • 7,636
  • 3
  • 32
  • 53