Android: AsyncTask ProgressDialog will not open in ActivityGroup -


i trying have a progress dialog open when polling server. class activitygroup because nested within tab bar. keep view within frame, activitygroup needed. here declaration of activitygroup class:

   public class checkinactivity extends activitygroup{         ...         public void oncreate(bundle savedinstancestate){         super.oncreate(savedinstancestate);         setcontentview(r.layout.checkin);             new locationcontrol().execute(this); 

now asynctask class within same checkinactivityclass such:

private class locationcontrol extends asynctask<context, void, void>     {         private final progressdialog dialog = new progressdialog(checkinactivity.this);          protected void onpreexecute()         {             this.dialog.setmessage("determining location...");             this.dialog.show();         } 

when run given app throughs error relating windowmanager$badtokenexception. stating cannot start window unknown token. tried making sample app regular activity(not activitygroup) , worked fine.

does know how modify make work, or work around allow progress bar nested within tab bar? appreciated.

if activitygroup within tabactivity have nested activities more 2 levels. android doesn't support @ moment there workaround. have pass parent activity dialog.

create helper method purpose in activity class:

private context getdialogcontext() {     context context;     if (getparent() != null) context = getparent();     else context = this;     return context; } 

then change line

private final progressdialog dialog = new progressdialog(checkinactivity.this); 

to

private final progressdialog dialog = new progressdialog(getdialogcontext()); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -