How to launch an activity with a specific tab?

前端 未结 2 739
花落未央
花落未央 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-09 23:27

    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
    }
    

提交回复
热议问题