0

在我的应用程序中,我有 2 个活动,第一个是每个页面中带有列表的操作栏,第二个是设置活动,您可以在其中设置操作栏包含的数量和选项卡。一切正常,但最后一件事,我无法完成的是,当我设置设置并单击按钮时,如何回到第一个活动。我不想将意图和启动活动作为新的传递,因为 JSONRpc 客户端正在启动并且需要一段时间才能连接等,这会很烦人。我尝试完成()第二个活动并调用 setActionBar onResume(),但它正在工作......有什么想法吗?谢谢..继承人一些代码:

第一项活动:

 public void onCreate(Bundle savedInstanceState){
 super.onCreate(savedInstanceState);

 Rubriky = ((HNapp) this.getApplication()).getRubriky();
 count=((HNapp) this.getApplication()).getCount(); 

 int catIndex = savedInstanceState == null ? 0 :savedInstanceState.getInt("catIndex", 0);
 setUpActionBar(catIndex);
 }
 //my try
 public void onResume(Bundle savedInstanceState){
    super.onResume();
    int catIndex = savedInstanceState == null ? 0 : savedInstanceState.getInt("catIndex", 0);
    Rubriky = ((HNapp) this.getApplication()).getRubriky();
    count=((HNapp) this.getApplication()).getCount();
    setUpActionBar(catIndex);
}

 //setting up actionbar
 public void setUpActionBar(int selTab) {

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(false);

    CABNavHan handler = new CABNavHan(this);

        actionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_TABS);
        int i;
        for (i = 0; i < count; i++) {
            actionBar.addTab(actionBar.newTab().setText(Rubriky[i]).setTabListener(handler));
        }
    actionBar.setSelectedNavigationItem(selTab);
    actionBar.setDisplayUseLogoEnabled(true);
    }
4

2 回答 2

0
  1. 您是否已验证 count 正在按照您的预期更新 onResume (假设当您完成()设置活动时,它会返回到后台堆栈中的现有操作)?

  2. 我注意到 onResume 您正在对已填充的 UI 对象执行相同的行为。是否可能已经配置了此 UI 实例的 ActionBar 并且您需要更新它而不是重新创建它?从您提供的代码片段中很难分辨。

于 2012-08-23T08:26:49.463 回答
0

调用 onBackPressed(); 你想回到第一次活动的地方。

于 2012-08-23T08:32:54.353 回答