本文介绍了在TabActivity不运行onCreate方法活动时,点击第二次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 TabActivity ,其中包括3 标签。我设置 currentActivity 1 不是默认的, 0 。当我开始我的 TabActivity 我想通了,Activity0也运行,但Tabactivity展示活动1中,我设置为 currentActivity 接口。此外,当我点击TAB2(包括活性2),然后再次单击tba1或TAB0,他们不再次运行。因为我认为TabActivity只是让运行一次。我想重新启动每个activiy在标签每当我点击标签。我想保持这些微量以便单击后退按钮时,它应该是tracable。

I have a TabActivity which includes 3 tabs. And I set currentActivity as 1 not the default one, 0 . When I start my TabActivity I figured out that Activity0 also runs but Tabactivity shows the interface of Activity1 which I set as currentActivity. Furthermore when I click tab2 (include Activity2) and click again tba1 or tab0, they dont run again. As I think TabActivity just let to run one time. I would like to restart each activiy in tab whenever I click tabs. And I would like to keep these in trace so that when clicking back button it should be tracable.

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);
    }

}

}

推荐答案

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

set flag Intent.FLAG_ACTIVITY_CLEAR_TOP for your tab intents.

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);

这篇关于在TabActivity不运行onCreate方法活动时,点击第二次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 13:59