Created
June 7, 2014 10:45
-
-
Save dsaiztc/f63247de5e2db371ce78 to your computer and use it in GitHub Desktop.
AsyncTask in Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class MyTask extends AsyncTask<Void, String, Boolean> | |
{ | |
private ProgessDialog mProgressDialog; | |
public MyTask() | |
{ | |
mProgressDialog = new ProgressDialog(mActivity); | |
mProgressDialog.setTitle("ProgressDialog title"); | |
mProgressDialog.setMessage("ProgressDialog message..."); | |
} | |
@Override | |
protected void onPreExecute() | |
{ | |
mProgressDialog.show(); | |
} | |
@Override | |
protected Boolean doInBackground(Void... params) | |
{ | |
publishProgress("Doing first task..."); | |
// First task | |
publishProgress("Doing second task..."); | |
// Second task | |
return true; | |
} | |
@Override | |
protected void onProgressUpdate(String... values) | |
{ | |
mProgressDialog.setMessage(values[0]); | |
} | |
@Override | |
protected void onPostExecute(Boolean result) | |
{ | |
if (mProgressDialog.isShowing()) | |
{ | |
mProgressDialog.dismiss(); | |
} | |
// Last things to do | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment