0

I want to display a process dialog for a particular time in front of an activity while other tasks performed in background . i don't want to use asynkTask as am updating the ui inside that method. please help

Charles
  • 50,943
  • 13
  • 104
  • 142
Jitendra
  • 37
  • 2
  • 7

1 Answers1

4

Take a look at your AsycTasks methods onPreExecute(...) and onPostExecute(...). Use the first to show the ProgressDialog, and the second to dismiss it when the task is finished.

OnPreExecute() will be called before your background-process starts. OnPostExecute() will be called when your task has finished.

// the below code is inside your asynctask class

private ProgressDialog pd;

@Override
protected void onPreExecute(){ 
   super.onPreExecute();

   pd = new ProgressDialog(context);
   pd.setMessage("Processing...");
   pd.show();    
}

@Override
protected Void doInBackground(Void... params) {
    // do stuff
    return null;
}

@Override
protected void onPostExecute(Void result){
   super.onPostExecute(result);
   pd.dismiss();
}
Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187