I am using default template provided by android studio to create tabbed activity with fragments .Every thing is working fine.I have 2 tabs in it, one for wifi and another for mobile network. What I want to do is on app startup check whether user is connected with wifi or mobile network.If wifi navigate him directly to wifi tab and vice versa.
I tried using connectivity manager to detect netwotk connection but not able to switch tabs properly. I didn't find correct place where and how should I change tabs

```
public class MainActivity extends AppCompatActivity {

TextView title;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    title= (TextView) findViewById(R.id.toolbar_title);
    Fonts.setMonthoersFont(this,title);

    SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    ViewPager mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);

}

/**
 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
 * one of the sections/tabs/pages.
 */
public class SectionsPagerAdapter extends FragmentPagerAdapter {

    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);

    }
    @Override
    public Fragment getItem(int position) {
           switch (position) {

            case 0:
                return FragmentWifi.newInstance(0);
            case 1:
                return FragmentMobileNetworks.newInstance(1);
            default:
                return new Fragment();
        }

        // getItem is called to instantiate the fragment for the given page.
        // Return a PlaceholderFragment (defined as a static inner class below).
        //
    }

    @Override
    public int getCount() {
        // Show 3 total pages.
        return 2;
    }

    @Override
    public CharSequence getPageTitle(int position) {

        switch (position) {
            case 0:
                return "Wi-Fi";
            case 1:
                return "Mobile Network";
        }
        return null;
    }
}

```

}