Navigation in Multi-page Apps | Part 1

Jun 22, 2021·

2 min read

Navigation in Multi-page Apps | Part 1

Hey people, I am Sanjay, and in this article, I explain how you can create multiple pages and navigate between them.

To add multiple pages, we have two options:
1. Traditional way
2. Jetpack way

If you want the code, I have created a sample project to demonstrate navigation you can download from that.
Android-Multipage-Sample | Github

Traditional way

In the previous article, we have discussed the app components where we introduced the concept of Activities. Please read that first if you don’t know what the activities are.

In this method, we use activities as separate pages and use Intents to navigate between them.

In the above code, we created an instance of Intent. As a first parameter, we passed the context (i.e here this as Activity) and as a second parameter, we passed the name of the destination activity. To launch this Intent, we can use the startActivity method in the Context class. Since the Activity is a subclass of the Context class, we can call it simply startActivity.

So by default Android Studio will create a Launcher Activity for us when we create a new project. We can use this Activity as a start activity.
Let’s create another Activity as a Target Activity.

Right-click the package name, then New -> Activity -> Empty Activity

So here we are going to place a button in Start Activity to launch an Intent to Target Activity.

In the Kotlin file, set a click listener as below.

You are all set up.

Hey, that’s the end of this story. I hope you learned new things. Thanks for reading. Please wait for another part for passing data between screens. Thanks again.

If you like my story, leave a clap below, it will boost my motivation to create new content. Happy coding : )