Wednesday, February 15, 2012

ProgressDialog will not open in ActivityGroup in Android?


If the ActivityGroup is within a TabActivity you have nested activities with more then two levels. Android doesn't support this at the moment but there is a workaround. You have to pass the parent activity to the dialog.
Create a helper method for this purpose in the activity class:
private Context getDialogContext() {
    Context context;
    if (getParent() != null) context = getParent();
    else context = this;
    return context;
}
Then change the line
private final ProgressDialog dialog = new ProgressDialog(CheckInActivity.this);
to
private final ProgressDialog dialog = new ProgressDialog(getDialogContext());

No comments:

Post a Comment