Android Basics - How to show back button on an Activity?


You should have at-least two activities.

  • Parent activity from which another activity is getting displayed.
  • Another activity which is shown from parent activity.

Example:

  • Login activity = Parent activity = LoginActivity
  • Forgot Password activity = Child activity = ForgotPasswordActivity

How to set up?

  1. Open AndroidManifest.xml
  2. Locate child activity, in my case it is ForgotPasswordActivity & replace it as follows.
<activity android:name=".LoginActivity" />

<activity android:name=".ForgotPasswordActivity">
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".LoginActivity" />
</activity>

Demo Output for Android