How to launch an activity with a specific tab?

不想你离开。 提交于 2019-12-03 09:03:48

You will need to handle it yourself with setCurrentTab in the new activity's constructor.

While calling, you should put additional values in the intent -

Intent i = new Intent(this, MyTabActivity.class);
i.putExtra("FirstTab", 4);

And in constructor of MyTabActivity -

Intent i = getIntent();
int tabToOpen = i.getIntExtra("FirstTab", -1);
if (tabToOpen!=-1) {
    // Open the right tab
}

try this with your tab position

Intent intent = new Intent(MyActivity.this, TabScreenActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.putExtra(ConstantString.ViewTab,1); startActivity(intent);

And in constructor of TabScreenActivity

if (getIntent() != null) {

        tabPosition = getIntent().getIntExtra(ConstantString.ViewTab, tabPosition);

        if (tabPosition == 1) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    viewPager.setCurrentItem(1, true);
                }
            }, 1000);
        } else {
            viewPager.setCurrentItem(0, true);
        }


    } else {
        viewPager.setCurrentItem(0, true);
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!