简体   繁体   English

通过意图调用Tabactivity后更改当前选项卡

[英]change current tab after calling tabactivity by intent

I am having a Tabactivity with two tabs and I am calling this tab activity from other activities ..but I want to set tab according to activity from where tab activity has been called .For that I have used intent flag SINGLE TOP and override onNewIntent() in Tabactivity so that I can find from where Tabactivity has been called and set tab according to that but my onNewIntent() is not getting called ..dont know why ..I have also mentioned launch mode SINGLE TOP ..Here is my Code for intent and onNewINtent(). 我有一个带有两个选项卡的Tabactivity,我从其他活动中调用此选项卡活动..但是我想根据调用了选项卡活动的活动来设置选项卡。为此,我使用了意图标志SINGLE TOP并覆盖onNewIntent( )中的Tabactivity,以便我可以从那里找到调用Tabactivity并据此设置tab,但是我的onNewIntent()没有被调用..不知道为什么..我也提到了启动模式SINGLE TOP ..这是我的代码用于intent和onNewINtent()。 Is there any other way to do this.. 还有其他方法可以做到这一点。

Intent i =new   Intent(Activity1.this,TabViewActivity.class);
i.putExtra("show","mytab");
i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i);


    @Override
    protected void onNewIntent(Intent intent) {
        // TODO Auto-generated method stub
        Log.e("new Intent","new intent has came ");
        if(intent.getExtras().getString("show").equalsIgnoreCase("mytab"))
        {
              View tabView = getTabWidget().getChildAt(0);
              tabView.findViewById(R.id.tabSelectedDivider).setVisibility(View.VISIBLE);
              tabHost.setCurrentTab(0);   
        }

        super.onNewIntent(intent);
    }
this.getIntent().getExtras() != null) { 
bundle = this.getIntent().getExtras();
}

can use this also inside oncreate no need for onNewIntent(). 也可以在oncreate内使用它,而无需onNewIntent()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM