title: Unable to implement back arrow on supportActionbar in dashboard activity
body: <p>I am unable to show back button on toolbar.I have a main activity Dashboard activity and many fragments.I want to show back button on toolbar if there are fragments in backstack.How can i implement it here is my dashboardActivity.java class file.And please tell if it is best method to implements fragments or manageable only.And i also want to add a social share icon on right side of toolbar.Is this possible with this type of toolbar or not.I have removed import statements to make question sorter.Any help would be highly appreciated.                                                             </p>
  
  <pre><code>            package com.example.narmail.MyApp.Api.Activities;
  
  
          public class DashboardActivity2 extends AppCompatActivity implements OnNavigationItemSelectedListener {
  
              public static Activity activity = null;
              public String token = null;
              public static Boolean truck = false;
              NavigationView navigationView;
              DrawerLayout drawerLayout;
              Toolbar toolbar;
              ActionBarDrawerToggle actionBarDrawerToggle;
  
              @Override
              protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  final AlphaAnimation buttonClick = new AlphaAnimation(1F, 0.7F);
                  buttonClick.setDuration(300);
  
                  activity = this;
  
                  setContentView(R.layout.activity_dashboard);
                  setToolbar();
                  getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                  navigationView = findViewById(R.id.nav_view);
                  navigationView.setNavigationItemSelectedListener(this);
              }
  
              @Override
              public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                  Fragment fragment = null;
                  switch (item.getItemId()) {
                      case R.id.nav_home:
                          Intent a = new Intent(DashboardActivity2.this, DashboardActivity2.class);
                          startActivity(a);
                          // fragment = new DashboardFragment();
                          break;
                      case R.id.nav_post_load:
                          fragment = new PostLoadFragment();
                          break;
                      case R.id.nav_add_truck:
                          fragment = new AddTruckFragment();
                          break;
                      case R.id.nav_manage_truck:
                          fragment = new ManageTruckFragment();
                          break;
                      case R.id.nav_manage_load:
                          fragment = new ManageLoadFragment();
                          break;
                      case R.id.nav_signout:
                          signoutAlert();
                          break;
  
                  }
                  if (fragment != null) {
                      FragmentManager fragmentManager = getSupportFragmentManager();
                      fragmentManager.beginTransaction()
                              .replace(R.id.screen_area, fragment).addToBackStack(null).setCustomAnimations(R.animator.enter_from_left, R.animator.exit_to_right).commit();
                  } else {
                      fragment = new DashboardFragment();
                      FragmentManager fragmentManager = getSupportFragmentManager();
                      fragmentManager.beginTransaction()
                              .replace(R.id.screen_area, fragment).commit();
                  }
                  drawerLayout = findViewById(R.id.drawerLayout);
                  drawerLayout.closeDrawer(GravityCompat.START);
                  return true;
              }
  
              private void setToolbar() {
                  drawerLayout = findViewById(R.id.drawerLayout);
                  toolbar = findViewById(R.id.toolbar);
                  setSupportActionBar(toolbar);
                  //  getSupportActionBar().setHomeAsUpIndicator(R.drawable.back_arraow);
                  toolbar.setNavigationIcon(R.drawable.back_arraow);
                  toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          Log.w("185 ", "back button pressed");
                          // back button pressed
                      }
                  });
  
                  actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.app_name, R.string.app_name);
                  drawerLayout.addDrawerListener(actionBarDrawerToggle);
                  actionBarDrawerToggle.syncState();
              }
  
              // Before 2.0
              public void onBackPressed() {
                  if (getSupportFragmentManager().getBackStackEntryCount() &gt; 0) {
                      getSupportFragmentManager().popBackStack();
                  } else {
                      Intent intent = new Intent();
                      intent.setAction(Intent.ACTION_MAIN);
                      intent.addCategory(Intent.CATEGORY_HOME);
                      startActivity(intent);
                  }
              }
  
              public void signoutAlert() {
                  new AlertDialog.Builder(this)
                          .setMessage("Are you sure you want to Signout?")
                          .setCancelable(false)
                          .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int id) {
                                  UserApi.logOut(DashboardActivity2.this);
                              }
                          })
                          .setNegativeButton("No", null)
                          .show();
              }
  
          }
  </code></pre>
  
  <p>and here is dashboardActivity.xml file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
          &lt;android.support.v4.widget.DrawerLayout android:id="@+id/drawerLayout"
              android:layout_height="match_parent"
              android:layout_width="match_parent"
              android:fitsSystemWindows="true"
              xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
             &lt;LinearLayout
                  android:id="@+id/my_screen"
                  android:layout_width="match_parent"
                  android:orientation="vertical"
                  android:layout_height="match_parent"&gt;
                  &lt;android.support.v7.widget.Toolbar
                      android:id="@+id/toolbar"
                      android:layout_width="match_parent"
                      android:background="@color/colorPrimary"
                      android:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
                      android:layout_height="wrap_content"&gt;
  
                  &lt;/android.support.v7.widget.Toolbar&gt;
                 &lt;include layout="@layout/content_main"&gt;
                 &lt;/include&gt;
              &lt;/LinearLayout&gt;
             &lt;android.support.design.widget.NavigationView
                 android:id="@+id/nav_view"
                 android:layout_width="wrap_content"
                 android:layout_gravity="start"
                 app:menu="@menu/drawer_menu"
                 app:headerLayout="@layout/header"
                 android:layout_height="wrap_content"&gt;
             &lt;/android.support.design.widget.NavigationView&gt;
  
          &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>