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 {

protected Void doInBackground(Void... params) {
protected void onPostExecute(Void result) {
protected void onProgressUpdate(Integer... progress) {


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


Popular posts from this blog

Open Gallery and get the selected image in appplication

Dismiss or Cancel dialog by swipe gesture

AlarmManager and Notification in Android