开发者

how a wait and then restart. (android)

Hi I got a service in android and I want it to update something every 10 seconds. So I was thinking of having a wait and then restart the function (cant think of what to call it). Any开发者_运维问答 ideas on how to do a wait in a service?


You will want to use threading. This can be done with something like this.

public void onClick(View v) {  
new Thread(new Runnable() {   
 public void run() {      
//Your code for whatever goes in here
  }
  }).start();
}

You can then call thread.sleep(10000). The 10000 translates to 10 seconds.

If you look at the accepted answer on this post the posters code shows all of this in an excellent way to understand.

Old SO Post


Use thread in your service and for wait use thread.sleep(10000)...


Use an AlarmManager. This will run your service at your scheduled time, and stops the service when it's done, ready to start again via the AlarmManager.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜