It depends on whether you want to use another thread or not. Do you want the user to be able to interact with the application in the user interface thread when loading images? If so, then I would definitely use AsyncTask with a little ProgressBar ( style="@android:style/Widget.ProgressBar.Small" )
If you don't care about threads, what @inazaruk said.
Edit:. True, these are the most modern applications that retrieve data from a web service, will use AsyncTask with a careful little bootloader in the corner to let the user know its update.
Edit 2: here is an example of using TimerTask to start something every 5 seconds. The key is runOnUiThread() . There may be better ways to link all the elements together , but this accurately displays all the fragments.
myTimer = new Timer(); myTimer.schedule(new TimerTask() { @Override public void run() { CallWebService(); } }, 0, 1000); } private void CallWebService() { this.runOnUiThread(fetchData); } private Runnable fetchData = new Runnable() { public void run() { asyncTask.execute(); } };
citizen conn
source share