How to Add Back Arrow in Android Activity

Here is a simple method to add a back arrow to other Activity to come back to MainActivity. To enter a new activity we create an Intent then start a new Activity using that intent instance using the startActivity method.

After we enter the new activity we add a listener on action bar instance to finish other activity to come back to MainActivity.

Let’s Start Coding…

Step 1) Here I will give an example of simple Empty Activity new project. I which we will create a new Activity.


Step 2) In res >> layout >> activity_main.xml we will add a button which will open a new other activity.


we added a button “OPEN OTHER ACTIVITY” with onClick even “openActivity


In “openActivity” event we will open OtherActivity using Intent


Step 3) Now right click on the main package and create a new activity named “OtherActivity


Step 4) Now we add back button and handle event listener in OtherActivity



When the user selects an item from the options menu (including action items in the app bar), the system calls your activity’s onOptionsItemSelected() method. 

Here we are finishing current Activity which is Other Activity to go back to main Activity.

Find source in Google Drive here

Thanks for visiting :) Let me know if you have some suggestions or feedback for this post in the comment section. Looking for any tutorial or demo on FreakyJolly, just drop me a message here

Leave a Reply

Notify of