Navigation in Multi-page Apps | Part 1

Sanjay S
2 min readJun 22, 2021

--

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.

layout XML of Start 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 : )

Original Post: https://sanjaydev.tech/blog/navigation-in-multi-page-apps-part-1-97d4c83f3277

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sanjay S
Sanjay S

Written by Sanjay S

Google Certified Associate Android Developer

No responses yet

Write a response