1

我有一个TabActivity包括 3 tabs。我设置currentActivity1不是默认的,0. 当我启动时,我TabActivity发现 Activity0 也运行,但 Tabactivity 显示了我设置为 Activity1 的界面currentActivity。此外,当我单击 tab2(包括 Activity2)并再次单击 tba1 或 tab0 时,它们不会再次运行。正如我认为 TabActivity 只是让运行一次。每当我单击选项卡时,我想重新启动选项卡中的每个活动。而且我想跟踪这些,以便在单击后退按钮时应该可以跟踪。

public class ActivityInTab extends TabActivity implements OnTabChangeListener{
TabHost tabHost;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activityintab);

    tabHost = getTabHost();

    TabSpec meSpec = tabHost.newTabSpec("Ben");
    meSpec.setIndicator("Ben", getResources().getDrawable(R.drawable.icon_me));
    Intent meIntent = new Intent(this, MeActivity.class);
    meSpec.setContent(meIntent);

    TabSpec searchSpec = tabHost.newTabSpec("Arama");
    searchSpec.setIndicator("Çevrende Ara", getResources().getDrawable(R.drawable.icon_search));
//        Intent searchIntent = new Intent(this, SearchActivity.class);
//        searchSpec.setContent(searchIntent);

    TabSpec resultSpec = tabHost.newTabSpec("Aradıklarım");
    resultSpec.setIndicator("Arama  Sonuçlarım", getResources().getDrawable(R.drawable.icon_result));
//        Intent resultIntent = new Intent(this, ResultActivity.class);
//        resultSpec.setContent(resultIntent);       

    tabHost.addTab(searchSpec); 
    tabHost.addTab(meSpec);
    tabHost.addTab(resultSpec);
    tabHost.setCurrentTab(1);

    tabHost.setOnTabChangedListener(this);

}

@Override
public void onTabChanged(String tabId) {
    if(tabId.equals("Ben") && tabHost.getCurrentTab()==0){
        MeActivity meact = (MeActivity) getLocalActivityManager().getActivity(tabId);

    }

    if(tabId.equals("Arama") && tabHost.getCurrentTab()==1){
        SearchActivity sact= (SearchActivity) getLocalActivityManager().getActivity(tabId); 
    }
    if(tabId.equals("Aradıklarım") && tabHost.getCurrentTab()==2){
        ResultActivity ract = (ResultActivity) getLocalActivityManager().getActivity(tabId);
    }

}

}

4

1 回答 1

2

为您的标签意图设置标志Intent.FLAG_ACTIVITY_CLEAR_TOP

Intent meIntent = new Intent(this, MeActivity.class);
meIntent .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

还有像这样的评论标签

Intent searchIntent = new Intent(this, SearchActivity.class);
 searchIntent .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
于 2013-04-12T09:26:24.607 回答