Creating Android Notepad App: 2. Setting up Navigation between Activities using Action Bar

In this part you will learn how to setup Navigation between two activities using Action Bar. So let’s start….!

Topics Covered

i. Setup Application Icon

Whenever you make your own app, your application must have unique icon to identify your app between other apps on the user’s phone.
In this tutorial we are going to use below icon as application icon and on action bar too as well.
I hope you already download all the icons set from previous part and copied it into resource folder in their respective folders.
Open AndroidManifest.xml from the project. And set the icon attribute value as “@drawable/notepad_icon” under application node. See the below.

Now open main.xml from layout folder. You must see the icon before application title. See the image below.
Creating Notepad Application in Android

ii. Adding option menus on Action Bar for Main Activity

Open and previously created menu_main.xml from the res>menu folder. Add the function onCreateOptionsMenu in file as shown below and set the menu_main.xml to set menu options.


Now run the application to see the result.
Creating Notepad Application in Android

iii. Creating Note Activity

Before go to Note Activity we have to create Note Activity and it into AndroidManifest.xml under application node.
So, let’s create new Class named “” and extend it by Activity class.

Now set the previously created note.xml as layout of the Note Activity. See the below code snippet.


Now add Note activity to AndroidManifest.xml under application node.

iv. Navigate Activities using Action Bar option menu

Main Activity to Note Activity
Creating Notepad Application in Android
To go on Note Activity, open the and add function onOptionsItemSelected. Now add following code snippet in the function to go to the Note Activity by pressing Add icon.

Note Activity to Main Activity
Creating Notepad Application in Android
To come back from Note Activity to Main Activity, we don’t need to do much with coding. Just open AndroidManifest.xml and add new attribute to Note activity node android:parentActivityName and set its value as “com.ajaybadgujar.notepad.Main” Activity class.
Now run the application to see the result.

v. Setting Option menu to Note Activity

Now setup option menu to Note Activity. i.e. Save button/icon on Action Bar.
Creating Notepad Application in Android
Open and add function onCreateOptionsMenu and set menu_note.xml to setup option menu on Action Bar. See the code below.

Download Part 2 Source

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *