Let’s say I have an Activity which displays a View containing a TextView.
My Activity also have an AsyncTask (running continuously) which retrieve data (a changing value) from a web server every second or so.
What I want is to monitor the data from the web server by displaying it in the TextView.
So far I always ask my AsyncTask to do the setText in the onProgressUpdate, so my TextView‘s display is refreshed every time I get new data… is there a better way ?
Thanks for reading me.
PS : In the end, I’ll have at least two Activities, both having an AsyncTask of the previously described variety.
If you want to separate the data and display a bit more, you could follow a listener pattern:
Make your Activity implement a new interface – something like:
and the implementation (in your Activity):
And a AsyncTask that looks something like this:
Your Activity keeps control of the UI, the AsyncTask downloads and notifies when something is updated.