Back arrow button also known as UP button are on of the most useful part of every android application because this icon will provide direct back button navigation to application user and by clicking on it the user will redirect to back activity.

To set the action bar,

// Initialize the toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

// Back button from action bar :
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);

// Hide the action bar
getSupportActionBar.hide();
 
// Show the action bar
getSupportActionBar.show();

// set the icon
getSupportActionBar.setIcon(R.drawable.ico_actionbar);

// #1 Add click listner 
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
    startActivity(new Intent(getApplicationContext(),MainActivity.class));
  }
});

// #2 Handle the back button 
@Override
public boolean onSupportNavigateUp() {
  onBackPressed();
  return true;
}

// #3 React to the user tapping the back/up icon in the action bar 
@Override
public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
    case android.R.id.home:
      // Another possibility is to call 'finish()'
      getActivity().onBackPressed();
      return true;
    default:
      return super.onOptionsItemSelected(item);
  }
}