Reputation: 18639
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!
Upvotes: 0
Views: 91
Reputation: 4607
Niek is right about the pre execute not being called. However, it seems to me that what you probably want is ProgressDialog. You can set it up like this
ProgressDialog progress = new ProgressDialog(context);
progress.setMessage("Loading Message");
progress.setTitle("Title");
progress.show();
Then, in onPostExecute, you will call
progress.dismiss();
To remove it. If you need something that looks more custom, you can subclass progress dialog to add a custom image/ other customizations.
Upvotes: 1
Reputation: 100388
Your onPreExecute
method is never called, because you are not overriding it properly.
The correct method signature should be:
@Override
protected void onPreExecute(){
//Your code
}
As a general tip, always use the @Override
annotation when overriding methods. When you try to override a method that doesn't exist, or when you've typed something wrong, an error appears.
Upvotes: 1