Basic structure of AsyncTask Class


private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
    protected Long doInBackground(URL... urls) {
        while (true) {
            // Do some work
            publishProgress((int) ((i / (float) count) * 100));
        }
       return result;
    }
    protected void onProgressUpdate(Integer... progress) {
        setProgressPercent(progress[0]);
    }
    protected void onPostExecute(Long result) {
        showDialog(“Result is “ + result);
    }
}

To execute,

new DownloadFilesTask().execute(url1, url2, url3);

To read more about async task refer android developer guide.

Comments

Popular posts from this blog

Fatal: LoadModule: error loading module 'mod_sql_mysql.c'

How to hide Android Soft Keyboard