开发者

AsyncTask loop doInBackground()

开发者 https://www.devze.com 2023-02-20 17:46 出处:网络
I\'m creating an application which communicates开发者_StackOverflow中文版 with a web service. I have a method heartBeat I would like to call asynchronous every 5secs or so. My problem is not how to

I'm creating an application which communicates开发者_StackOverflow中文版 with a web service.

I have a method heartBeat I would like to call asynchronous every 5secs or so. My problem is not how to do this asynchronous. But how I keep the job done. I use a inner class which inherit from AsyncTask. My question is how can I start this thread every 5sec?

I have tried something like from doInBackground()

while (true) {
  ...
  Thread.sleep(5000);
}

but I also need the return statement, to tell the UI thread whatever the web service is available or not.


You can use publishProgress() from within doInBackgroound() and then do UI stuff in onProgressUpdate()

0

精彩评论

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

关注公众号