AsyncTask in Android

AsyncTask allows us to do proper background operations without creating threads and handlers. AsyncTask will run in the background thread and whose results we can pass to the UI thread. To implement AsyncTask, what we need to do is, create a class which extends AsyncTask and need to override some methods in it like doInBackground(), onPostExecute(), onProgressUpdate().

Sample program is,

  
private class BackgroundTask extends AsyncTask {

@Override
protected Void doInBackground(Void... params) {
}
protected void onPostExecute(Void result) {
super.onPostExecute(result);
}
protected void onProgressUpdate(Integer... progress) {
}

}


We can call AsyncTask using, new BackgroundTask().execute();

Comments

Popular posts from this blog

AlarmManager and Notification in Android

Swipe Action and ViewFlipper in Android