Lets say Activity A has 5 buttons. Each button will take you to Activity B which is a tabbed activity with 5 tabs. When I click button1 I want it to take you to tab1, button2 = tab2, button3 = tab3, etc. I'm using setCurrentItem but it's only working for the first and last button. The rest in-between will take you to tab1.
What code do I need so button2 will take me to tab2. Do I need and if else statement? Help would be much appreciated. 

ActivityA.java

```
  public void Button1(View view) {
    Intent intent = new Intent(view.getContext(), TabbedActivity.class);
    intent.putExtra("Tab1", 0);  //2 or whatever you want
    startActivity(intent);
}

public void Button2(View view) {

    Intent intent = new Intent(view.getContext(), TabbedActivity.class);
    intent.putExtra("Tab2", 1);  //2 or whatever you want
    startActivityForResult(intent, 0);

}

public void Button3(View view) {

    Intent intent = new Intent(view.getContext(), TabbedActivity.class);
    intent.putExtra("Tab3", 2);  //2 or whatever you want
    startActivityForResult(intent, 0);

}

public void Button4(View view) {

    Intent intent = new Intent(view.getContext(), TabbedActivity.class);
    intent.putExtra("Tab4", 3);  //2 or whatever you want
    startActivityForResult(intent, 0);

}

public void Button5(View view) {

    Intent intent = new Intent(view.getContext(), TabbedActivity.class);
    intent.putExtra("Tab5", 4);  //2 or whatever you want
    startActivityForResult(intent, 0);

}

```

ActivityB.java

```
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);

    final int position1 = getIntent().getExtras().getInt("Tab1");

    final int position3 = getIntent().getExtras().getInt("Tab3");
    final int position2 = getIntent().getExtras().getInt("Tab2");
    final int position4 = getIntent().getExtras().getInt("Tab4");

    final int position5 = getIntent().getExtras().getInt("Tab5");

    PagerAdapter adapter = new PagerAdapter
            (getSupportFragmentManager(), tabLayout.getTabCount());
    viewPager.setAdapter(adapter);

    {
        viewPager.setCurrentItem(position1);
    }
    {
        viewPager.setCurrentItem(position3);
    }
    {
        viewPager.setCurrentItem(position2);
    }

    {
        viewPager.setCurrentItem(position4);
    }

    {

        viewPager.setCurrentItem(position5);
    }

```