AsyncTask loop doInBackground()
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()
精彩评论