Android supports the Javas concurrency library, but you should take a peek at AsyncTask , which supports ongoing operations both on the UI thread and in the background.
Here is a short example of a task:
private class CharCountTask extends AsyncTask<String, Integer, Long> { protected Long doInBackground(String... in) { long result = 0; for(int i=0,n=in.length; i<n; i++) { result += in[i].length(); publishProgress((int) (i / (double) count) * 100); } return result; } protected void onProgressUpdate(Integer... progress) {
To use it:
new CharCountTask().execute("first", "second", "third");
source share