How to start an event with a special tab?

I looked at a lot of examples, questions, and tutorials, but I never saw an activity launch (launch a new intent) with a special tab. I know that you can use to switch to a tab .setCurrentTab, but this can only be done on the parent activity tab. How about launching a specific tab contained in one action from another activity? Is it possible? If so, how?

In my code, on standard activity, the user launches the first tab, but I want him to go to the fourth tab if he is redirected from another action. My TabHost code (MyTabActivity):

int tabIndex = 0;

          mTabHost.addTab(mTabHost.newTabSpec("top10").setIndicator("Top 10").setContent(R.id.Top_10));
          mTabHost.addTab(mTabHost.newTabSpec("billable").setIndicator("Billable").setContent(R.id.Billable));
          mTabHost.addTab(mTabHost.newTabSpec("product").setIndicator("Product").setContent(R.id.Product));
          mTabHost.addTab(mTabHost.newTabSpec("regular").setIndicator("Regular").setContent(R.id.General));


          mTabHost.setCurrentTab(tabIndex);

Now in another action:

public void gotoTab() {
//This will take me to the first tab
Intent i = new Intent(this, MyTabActivity.class);
startActivity(i);
finish();
//How to I make it take me to the fourth tab?
}
+5
source share
2

setCurrentTab .

-

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

MyTabActivity -

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

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

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

All Articles