【问题标题】:TabGroupActivity : WindowManager$BadTokenException: Unable to add windowTabGroupActivity : WindowManager$BadTokenException: 无法添加窗口
【发布时间】:2013-09-14 07:31:23
【问题描述】:

当我要添加将 TabGroupActivity 扩展为 TabHost 的 Activity 时,我的应用程序崩溃了。Fallowing 是代码。当我直接添加主页时,一切正常,但是当添加 HomePageTabGroup 时,应用程序不幸关闭。

MainTabHost.java

public class MainTabHost extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.maintabhost);

    final TabHost tabHost = getTabHost();
    //tabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);


    // Tab for Home
    TabSpec home = tabHost.newTabSpec("Current Jobs");
    // setting Title and Icon for the Tab
    home.setIndicator("Current Jobs",getResources().getDrawable(R.drawable.icon_home_tab));
    Intent homeIntent = new Intent(MainTabHost.this, HomePageTabGroup.class);
    home.setContent(homeIntent);

   // Adding all TabSpec to TabHost
    tabHost.addTab(home); // Adding home tab

    }
}

HomePageTabGroup.java

public class HomePageTabGroup extends TabGroupActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    startChildActivity("HomePage", new Intent(HomePageTabGroup.this, HomePage.class));
    }

}

【问题讨论】:

    标签: android windows token android-tabactivity


    【解决方案1】:

    我终于得到了答案。

    在主页,有一个自定义的进度对话框,

    UmeshCustomProgressHUD.show(HomePage.this,"Loading\nPlease wait!", true,true,this);
    

    一切都是因为上面的线而发生的。我换了

    HomePage.this 
    

    HomePageTabGroup.ctx, 
    

    其中 ctx 被定义为 HomePageTabGroup 中的静态上下文。这两行代码解决了我的问题。

    【讨论】:

      猜你喜欢
      • 2013-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多