title: How to create an abstract activity class and extend it to all activities?
body: <p>I have navigation drawer menu and 6 activities. I want to create an abstract activity class, and move all my drawer menu code to it, and then extend it.</p>
  
  <p>This is my Main activity.java and my drawer's code in this activity.</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  private Toolbar toolbar;
  protected DrawerLayout drawerLayout;
  NavigationView navigationView;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
  
      TextView tv = (TextView)findViewById(R.id.textView);
      Typeface textfont = Typeface.createFromAsset(getAssets(),"fonts/B Roya_YasDL.com.ttf");
      tv.setTypeface(textfont);
  
      toolbar = (Toolbar) findViewById(R.id.toolbar);
      drawerLayout = (DrawerLayout) findViewById(R.id.a1);
  
      setSupportActionBar(toolbar);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_more_vert_black_24dp);
      navigationView = (NavigationView) findViewById(R.id.a2);
      navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(@NonNull MenuItem item) {
              item.setChecked(true);
              drawerLayout.closeDrawer(Gravity.RIGHT);
              switch (item.getItemId()){
                  case R.id.intro:
                      Intent i = new Intent(MainActivity.this, IntroActivity.class);
                      startActivity(i);
                      break;
              }
  
  
  
              return false;
          }
      });
  
  }
  
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  public boolean onOptionsItemSelected(MenuItem item) {
      int id = item.getItemId();
      if (id == R.id.khat) {
          if (drawerLayout.isDrawerOpen(Gravity.RIGHT)) {
              drawerLayout.closeDrawer(Gravity.RIGHT);
          }
  
          else {
              drawerLayout.openDrawer(Gravity.RIGHT);
          }
          return super.onOptionsItemSelected(item);
      }
      else {
          Toast.makeText(getApplicationContext(),"somthing",Toast.LENGTH_LONG).show();
      }
  
  
      return true;
  }
  
  public void onBackPressed(){
      if (drawerLayout.isDrawerOpen(Gravity.RIGHT)){
          drawerLayout.closeDrawer(Gravity.RIGHT);
      }else {super.onBackPressed();}
  
  }
  </code></pre>
  
  <p>and this is my second activity for example:</p>
  
  <pre><code>public class IntroActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_intro);
  }
  </code></pre>
  
  <p>How can I create an abstract activity class and insert my drawer's code in there and call it from any activity that I want?</p>