ProgressBars and AsyncTasks
I was playing around with styling a ProgressBar and needed a thread type mechanism to update it. My goal was for the ProgressBar to do its thing and then disappear from the layout once it reached 100%. Initially I used a Thread, but this left me unable to get at the UI thread. Instead I created an AsyncTask. This is a very flexible mechanism for running background processes in Android. In order to use AsyncTask in Android you extend the class like this: class MyAsyncTask extends AsyncTask Those three types (Void, Integer and Void in my case) represent the parameters sent into the task, the progress of the task (which can be published periodically if you like) and the results of the task. The parameters and the progress are Varargs, although I only used the first slot of each in my simple example. My doInBackground looks like this: @Override protected Void doInBackground(Void... params) { while (mProgressStatus < 100) { publishProgress(doWork()); ...