title: How to merge two Activity in Android
body: <p>I am having an two Activity in my project. In my DrawerActivity, I have added Navigation Drawer and in other activity i.e TabActivity I have list of fragments. I am trying to show content of TabActivity in DrawerActivity.
  Is it possible to do so or I have follow another approach. I am newbie developer please help me out.</p>
  
  <p>DrawerActivity.java</p>
  
  <pre><code>import android.os.Bundle;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.view.View;
  import android.support.design.widget.NavigationView;
  import android.support.v4.view.GravityCompat;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v7.app.ActionBarDrawerToggle;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.Menu;
  import android.view.MenuItem;
  
  public class Drawer extends AppCompatActivity
          implements NavigationView.OnNavigationItemSelectedListener {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_drawer);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
  
          DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                  this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
          drawer.setDrawerListener(toggle);
          toggle.syncState();
  
          NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
          navigationView.setNavigationItemSelectedListener(this);
      }
  
      @Override
      public void onBackPressed() {
          DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          if (drawer.isDrawerOpen(GravityCompat.START)) {
              drawer.closeDrawer(GravityCompat.START);
          } else {
              super.onBackPressed();
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.drawer, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
      @SuppressWarnings("StatementWithEmptyBody")
      @Override
      public boolean onNavigationItemSelected(MenuItem item) {
          // Handle navigation view item clicks here.
          int id = item.getItemId();
  
          if (id == R.id.nav_camera) {
              // Handle the camera action
          } else if (id == R.id.nav_gallery) {
  
          } else if (id == R.id.nav_slideshow) {
  
          } else if (id == R.id.nav_manage) {
  
          } else if (id == R.id.nav_share) {
  
          } else if (id == R.id.nav_send) {
  
          }
  
          DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          drawer.closeDrawer(GravityCompat.START);
          return true;
      }
  }
  </code></pre>
  
  <p>// And my second activity is TabActivity, here i want to show content of this   activity in DrawerActivity.</p>
  
  <pre><code>package com.umenit.naviagtiondrawer;
  
  import android.os.Bundle;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.support.design.widget.TabLayout;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.View;
  
  import com.umenit.naviagtiondrawer.fragment.EightFragment;
  import com.umenit.naviagtiondrawer.fragment.FiveFragment;
  import com.umenit.naviagtiondrawer.fragment.FourFragment;
  import com.umenit.naviagtiondrawer.fragment.OneFragment;
  import com.umenit.naviagtiondrawer.fragment.SevenFragment;
  import com.umenit.naviagtiondrawer.fragment.SixFragment;
  import com.umenit.naviagtiondrawer.fragment.ThreeFragment;
  import com.umenit.naviagtiondrawer.fragment.TwoFragment;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class TabActivity extends AppCompatActivity {
  
      private Toolbar toolbar;
      private TabLayout tabLayout;
      private ViewPager viewPager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_tab);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
          viewPager = (ViewPager) findViewById(R.id.viewpager);
          setupViewPager(viewPager);
  
          tabLayout = (TabLayout) findViewById(R.id.tabs);
          tabLayout.setupWithViewPager(viewPager);
      }
  
      private void setupViewPager(ViewPager viewPager) {
          ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
          adapter.addFragment(new OneFragment(), "ONE");
          adapter.addFragment(new TwoFragment(), "TWO");
          adapter.addFragment(new ThreeFragment(), "THREE");
          adapter.addFragment(new FourFragment(), "FOUR");
          adapter.addFragment(new FiveFragment(), "FIVE");
          adapter.addFragment(new SixFragment(), "six");
          adapter.addFragment(new SevenFragment(), "SEVEN");
          adapter.addFragment(new EightFragment(), "EIGHT");
          viewPager.setAdapter(adapter);
      }
      class ViewPagerAdapter extends FragmentPagerAdapter {
          private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();
          private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();
  
          public ViewPagerAdapter(FragmentManager manager) {
              super(manager);
          }
  
          @Override
          public Fragment getItem(int position) {
              return mFragmentList.get(position);
          }
  
          @Override
          public int getCount() {
              return mFragmentList.size();
          }
  
          public void addFragment(Fragment fragment, String title) {
              mFragmentList.add(fragment);
              mFragmentTitleList.add(title);
          }
  
          @Override
          public CharSequence getPageTitle(int position) {
              return mFragmentTitleList.get(position);
          }
      }
  }
  </code></pre>