I have one activity. OnCreate the activity gets the source (html) of a web page to a string and presents the result (after parsing it a bit) in a textview.
I would like the activity to reload/refresh periodically to always present the latest information.
What is the best solution for this?
First of all… separate the updating logic from your
onCreatemethod. So, for instance, you can create anupdateHTML().Then, you can use a
Timerin order to update the page periodically:Notice that I’m canceling the updating task on
onPause, and that in this case theupdateHTMLmethod is executed each 40 secs (40000 milliseconds). Also, make sure you import these two classes:java.util.Timerandjava.util.TimerTask.