Android: AsyncTask ProgressDialog will not open in ActivityGroup

I am trying to have a a progress dialog open when polling my server. The class is an ActivityGroup because it is nested within a tab bar. To keep the view within the frame, the ActivityGroup is needed. Here is the declaration of my ActivityGroup class:

   public class CheckInActivity extends ActivityGroup{
        public void onCreate(Bundle savedInstanceState){
            new LocationControl().execute(this);

Now my AsyncTask class is within the same CheckInActivityClass as such:

private class LocationControl extends AsyncTask<Context, Void, Void>
        private final ProgressDialog dialog = new ProgressDialog(CheckInActivity.this);

        protected void onPreExecute()
            this.dialog.setMessage("Determining your location...");

When I run the given app it throughs an error relating to WindowManager$BadTokenException. Stating the it cannot start the window with an unknown token. I tried making a sample app that is just a regular Activity(not ActivityGroup) and it worked just fine.

Does anyone know how to modify this to make it work, or a work around that will allow the progress bar to be nested within the tab bar? Any help is greatly appreciated.


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);


private final ProgressDialog dialog = new ProgressDialog(getDialogContext());

Need Your Help

Google Map fetch dynamic LatLng index

javascript google-maps-api-3 latitude-longitude jsonobject

My code below trigger a simple Google Map event when the user click on the marker:

How do I yield to the message pump in Excel VBA 2010?

excel vba excel-vba message-queue

I have an Excel macro that takes an exceedingly long time. It seems to crash Excel (I get a Not Responding message in the taskbar) when I leave it unattended, but if I put a breakpoint that gets hit

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.