You can use AsyncTask for this
public class MyAsyncTask extends AsyncTask<Void, Integer, Boolean>
{
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
/** do your initialization here like setting up porgress bar or some other
variable it's up to you*/
}
@Override
protected Boolean doInBackground(Void... params) {
//do your work here
//update progress bar
publishProgress(total_progress);
return flag; //return true or false
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
//set progress here
progressbar.setProgress(values[0])
}
@Override
protected void onPostExecute(Boolean result) {
//deal with you alertdialog here
if(result)
{
//do something with our alert dialog
}
else
{
//do something with your alert dialoge
}
super.onPostExecute(result);
}
}