How to add back button on ActionBar in Android Studio?

Assuming that you have a DetailActivity and you need back button to MainActivity. First change your manifest to for DetailActivity

<activity
    android:name=".DetailActivity"
    android:label="@string/title_activity_detail"
    android:parentActivityName=".MainActivity">
  <meta-data
      android:name="android.support.PARENT_ACTIVITY"
      android:value="com.example.MainActivity"/>
</activity>

and in onCreate of DetailActivity

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

will fix things. This is the simplest implementation.