Skip to content

Instantly share code, notes, and snippets.

@dsaiztc
Created June 7, 2014 10:45
Show Gist options
  • Save dsaiztc/f63247de5e2db371ce78 to your computer and use it in GitHub Desktop.
Save dsaiztc/f63247de5e2db371ce78 to your computer and use it in GitHub Desktop.
AsyncTask in Android
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