1

我有一个需要 GCM 和 Tabhost 的项目,但是在同一个 MainActivity 类中声明它们会导致应用程序崩溃,并且我不能使用片段,因为我的应用程序需要向后兼容 Gingerbread。有谁知道解决方法?

编辑: 嗯,我找到了这个很好的教程,用于在预蜂窝版本中实现碎片标签,但我仍然遇到同样的问题。 http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/

如何以不干扰选项卡/反之亦然的方式实施 GCM?我错过了什么?

4

1 回答 1

0

毕竟 GCM 和 TabHost 似乎玩得很好。问题的根源原来不是,而是选项菜单。如果有人正在使用 Google 提供的 DemoActivity 库设置 GCM,请在撕掉头发之前检查这段讨厌的代码:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
   switch(item.getItemId()) {
       case R.id.options_register:
           GCMRegistrar.register(this, SENDER_ID);
           return true;
       case R.id.options_unregister:
           GCMRegistrar.unregister(this);
           return true;
       case R.id.options_clear:
           mDisplay.setText(null);
           return true;
       case R.id.options_exit:
           finish();
           return true;
       default:
           return super.onOptionsItemSelected(item);
   }
}    

我不够聪明,无法弄清楚为什么这是有问题的,但它不喜欢 TabHost 或使用 Fragments 创建的 Tabs(我都尝试过)。

于 2013-06-21T19:11:09.613 回答