How to launch an activity with a specific tab?

前端 未结 2 737
花落未央
花落未央 2021-02-09 23:01

I\'ve gone through many examples, questions and tutorials but I\'ve never seen an activity launch (launch a new intent) with a specific tab. I know that one can use .setCu

2条回答
  •  情书的邮戳
    2021-02-09 23:34

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

提交回复
热议问题