Reader small image

You're reading from  Modern Android 13 Development Cookbook

Product typeBook
Published inJul 2023
Reading LevelIntermediate
PublisherPackt
ISBN-139781803235578
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Madona S. Wambua
Madona S. Wambua
author image
Madona S. Wambua

Madona S. Wambua is a Google Developer Expert in the Android category, an Android Engineer programming in Kotlin, and the founder and Chief Technology Officer of Jibu Labs. She is also a Women Tech Makers Ambassador and Co-Chair of AnitaB. She has over ten years of experience in the field and has worked on consumer-facing applications and building software development kits for developers. She has also worked on the famous Google Glass during her tenure at a startup and got an opportunity to work on interactive AR videos to transform lives through machine learning and computer vision. Madona is also a Keynote Speaker and the host of Tech Talks with Madona, a podcast geared towards supporting women and allies in tech.
Read more about Madona S. Wambua

Right arrow

Navigation in Modern Android Development

In Android development, navigation is the interaction that allows your Android application users to navigate to, from, and back out from the different screens within your app, an action that is very vital in the mobile ecosystem.

Jetpack navigation has simplified navigation between screens, and in this chapter, we will learn how to implement navigation with a simple view click, from the bottom navigation bar, which is most commonly used, by navigating with arguments, and more.

In this chapter, we’ll cover the following recipes:

  • Implementing a bottom navigation bar using navigation destinations
  • Navigating to a new screen in Compose
  • Navigating with arguments
  • Creating deep links for destinations
  • Writing tests for navigation

Technical requirements

Implementing a bottom navigation bar using navigation destinations

In Android development, having a bottom navigation bar is very common; it helps inform your users that there are different sections in your application. In addition, other apps opt to include a navigation drawer activity, which holds a profile and additional information about the application.

An excellent example of an app that utilizes both – a navigation drawer and bottom navigation – is Twitter. It is also important to mention that some companies prefer to have a top navigation bar as a preference. In addition, others such as Google Play Store have both bottom and drawer navigation.

Getting ready

Create a new Android project with your preferred editor or Android Studio, or you can use any project from previous recipes.

How to do it…

In this recipe, we are going to create a new project and call it BottomNavigationBarSample:

  1. After creating our new empty Activity BottomNavigationBarSample...

Writing tests for navigation

Now that we have created a new screen for our SampleLogin project, we need to fix the broken test and add new tests for the UI package. If you can recall, in Chapter 3, Handling the UI State in Jetpack Compose and Using Hilt, we did unit tests and not UI tests. This means after adding all the ViewModel instances, our UI tests are now broken. In this recipe, we will fix the failing tests and add a navigation test.

Getting ready

In this recipe, you do not need to create any new project; use the already-created project, SampleLogin.

How to do it…

You can apply these concepts to test the bottom navigation bar we created. Hence, we will not be writing tests for the BottomNavigationBarSample project. Open SampleLogin and navigate to the androidTest package. We will add tests here for the new RegisterScreen() a Composable function, and also fix the broken tests:

  1. Let’s open the LoginContentTest class. Now, let’s move the...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Modern Android 13 Development Cookbook
Published in: Jul 2023Publisher: PacktISBN-13: 9781803235578
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Madona S. Wambua

Madona S. Wambua is a Google Developer Expert in the Android category, an Android Engineer programming in Kotlin, and the founder and Chief Technology Officer of Jibu Labs. She is also a Women Tech Makers Ambassador and Co-Chair of AnitaB. She has over ten years of experience in the field and has worked on consumer-facing applications and building software development kits for developers. She has also worked on the famous Google Glass during her tenure at a startup and got an opportunity to work on interactive AR videos to transform lives through machine learning and computer vision. Madona is also a Keynote Speaker and the host of Tech Talks with Madona, a podcast geared towards supporting women and allies in tech.
Read more about Madona S. Wambua