I am trying to display a dialog to the user when I invoke an AsynchTask.
I am trying to use the onPreExecute method like this:
protected void onPreExecute(Long result)
{
dialog = new Dialog(UpdateProfileActivity.this);
dialog.setContentView(R.layout.please_wait);
dialog.setTitle("Updating account details...");
dialog.show();
}
and then in onPostExecute method do this:
@Override
protected void onPostExecute(String result)
{
try {
dialog.dismiss();
} catch (Exception ee) {
// nothing
}
But the dialog does not show up. I looked at the documentation and even though there are mentions of onPreExecute, I am not sure how it is used. Mine is simply never called.
What is the proper use of it and how do I make sure the dialogs are properly opened and closed?
Thank you!
Your
onPreExecutemethod is never called, because you are not overriding it properly.The correct method signature should be:
As a general tip, always use the
@Overrideannotation when overriding methods. When you try to override a method that doesn’t exist, or when you’ve typed something wrong, an error appears.