COURSE 11: ANDROID APP CAPSTONE QUIZ ANSWERS

Week 2: Starting the Project

Meta Android Developer Professional Certificate

Complete Coursera Answers & Study Guide

Click to Enroll in Coursera Meta Front-End Professional Certificate

Starting the Project INTRODUCTION

In this module you will be guided through the process of creating an onboarding flow for your app. You will also set up the navigation for your app and create a user profile page. Thereafter you will be required to develop the user interface of the food menu for the Little Lemon app. This will include processes such as fetching data and then filtering menu items.

Learning Objectives

  • Set up the UI flow of the user onboarding for an application
  • Set up the user interface of a food ordering application

READINESS CHECK: DID YOU SET UP THE USER ONBOARDING?

1. In the exercise Set up the onboarding page, which element did you use to represent a text input?

  • Text Composable
  • UIText Composable
  • TextField Composable  (CORRECT)

That’s correct. The TextField composable is a Jetpack Compose text input view.

2. After completing this exercise, you should have four elements that appear on the onboarding screen. 

  • True
  • False  (CORRECT)

That’s correct. There are five elements: an image, three text fields and a button.

3. In the exercise Set up the onboarding page, what was the name of the callback attribute used to persist values from the Text Composables?

  • onValueChange  (CORRECT)
  • onDataChange
  • onTextChange

That’s correct. The Text Composable callback’s name is onValueChange.

4. Your app should let users who are already logged in skip the onboarding and directly access the Home screen. What is required to implement this functionality? Select all that apply.

  • Checks whether the user has already completed the onboarding and navigate to the appropriate screen  (CORRECT)
  • Acquire WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE system permission
  • Store user data in persistent storage on the device  (CORRECT)

That’s correct! On app launch the application should check if the is already onboarded and navigates to the appropriate screen.

That’s correct! Information that a user has entered during onboarding needs to be stored in persistent storage on the device.

READINESS CHECK: DID YOU SET UP THE NAVIGATION FLOW?

1. After completing the exercise Set up the navigation, what screens does your Little Lemon food ordering app have? Select all that apply.

  • Login screen
  • Profile screen  (CORRECT)
  • Home screen
  • Onboarding screen  (CORRECT)

That’s correct. Your Little Lemon food ordering app should have a profile screen.

That’s correct. Your Little Lemon food ordering app should have a home screen.

That’s correct. Your Little Lemon food ordering app should have an onboarding screen.

2. In the exercise Set up the Navigation, how did you handle button clicks?

  • onClick = {}  (CORRECT)
  • Modifier.onTap {}

That’s correct. This callback is fired when a button is clicked.

3. In the exercise Set up the Navigation, what command did you use to navigate to the home destination?

  • DishDetails.show()
  • navController.navigate(“home”)  (CORRECT)

That’s correct. This command uses the navigation controller to navigate to the home destination.

4. In the exercise Set up the Navigation, which Jetpack navigation elements did you use? Select all that apply.

  • NavHost  (CORRECT)
  • NavFlow
  • NavGraph  (CORRECT)
  • NavManager
  • NavController  (CORRECT)

That’s correct. The NavHost component was used.

That’s correct. The NavGraph component was used.

That’s correct. The NavController component was used.

READINESS CHECK: DID YOU SET UP THE USER PROFILE PAGE?

1. In the exercise Set up the profile screen, which element did you use to represent static text elements?

  • TextField Composable
  • Text Composable (CORRECT)
  • UITextField Composable 

That’s correct. The Text Composable is a Jetpack Compose element that displays text on the screen.

2. After completing the Set up the profile screen exercise, you should have four elements that appear on the profile screen.  

  • True
  • False (CORRECT)

That’s correct. There are six elements: the logo in the header, the text “Profile information:”, three text fields and a button. 

3. In the Set up the profile screen exercise, which container was used to position elements on the screen? 

  • LinearLayout
  • Column  (CORRECT)
  • Row

That’s correct. The Column Composable was used to position items below one another other. 

READINESS CHECK: DID YOU COMMIT YOUR PROGRESS TO GIT?

1. Which command should you use to create a new Git branch?

  • git checkout <branch-name>
  • git checkout –b <branch-name>  (CORRECT)

That’s correct. This creates a new branch in Git.

2. Which command is correct for committing the changes of a Git branch?

  • git commit –m “message”  (CORRECT)
  • git commit “message”

That’s correct. This command commits the change and provides a new message that describes the changes.

3. Which of the following commands is used for pushing changes to a GitHub repository?

  • push –u origin <branch-name>  (CORRECT)
  • push –u origin

That’s correct. This command pushes the changes to a GitHub repository.

KNOWLEDGE CHECK

1. What dependency do you need to add to build.gradle to add navigation support for Compose?

  • androidx.navigation:navigation-compose:$nav_version  (CORRECT)
  • androidx.compose:navigation:$nav_version 

That’s correct. This is the dependency required to add navigation support to Compose.

2. Which component is central to navigation in Jetpack Compose?

  • Intent
  • NavController  (CORRECT)
  • NavHost

That’s correct. NavController is the central component for navigation in Jetpack Compose.

3. What does the following code snippet do?

NavHost(navController = navController, startDestination = "menu") {
    composable("menu") { Menu(/*...*/) }
    composable("dishDetails") { DishDetails(/*...*/) }
    /*...*/
}
  • Creates a navigation graph with menu as the starting destination  (CORRECT)
  • Navigates to menu and then to dishDetails
  • Creates the menu and dishDetails Composables

That’s correct. By instantiating a NavHost with a navController, a start destination and Composable creates a navigation graph.

4. How many screens does the Little Lemon food ordering app have?

  • (CORRECT)
  • 4
  • 5

That’s correct. The Little Lemon food ordering app has 3 screens.

5. When is stored data cleared via SharedPreferences?

  • When the app is uninstalled  (CORRECT)
  • When the user clears the app data  (CORRECT)
  • When the device is restarted

That’s correct. Uninstalling the app will remove all data stored via SharedPreferences.

That’s correct. Clearing the app data will wipe the data stored via SharedPreferences.

READINESS CHECK: DID YOU FETCH AND STORE THE FOOD MENU?

1. Suppose the server returns the following JSON data:

{
"menu": [
{
"id": 1,
"title": "Spinach Artichoke Dip",
"price": "10"
},
{
"id": 2,
"title": "Hummus",
"price": "10"
},
{
"id": 3,
"title": "Fried Calamari Rings",
"price": "51"
]
}

Which data classes do you need to decode this into a suitable Kotlin format? 

@Serializable
data class MenuNetwork(
    @SerialName("menu")
    val menu: List<MenuItemNetwork>,
)
@Serializable
data class MenuItemNetwork(
    @SerialName("id")
    val id: Int,
    @SerialName("title")
    val title: String,
    @SerialName("price")
    val price: Double,
) {
    fun toMenuItemRoom() = MenuItemRoom(
        id,
        title,
        price
   )
}

(CORRECT)

@Entity
data class MenuItemRoom(
    @PrimaryKey val id: Int,
    val title: String,
    val price: Double,
)

That’s correct. The first class will decode the menu and the second one decodes the menu items. 

2. Which dependencies were used to retrieve data from the network?

  • io.ktor:ktor-client-android:2.1.3
  • io.ktor:ktor-client-content-negotiation
  • io.ktor:ktor-serialization-kotlinx-json:2.1.3   (CORRECT)
  • androidx.room:room-runtime
  • androidx.room:room-compiler:2.4.3

That’s correct. These dependencies were used.

3. Which annotations are required to store data in the database using Room? Select all that apply.

  • @Dao (CORRECT)
  • @Entity  (CORRECT)
  • @Database  (CORRECT)

That’s correct. Dao annotation is used.

That’s correct. Entity annotation is used.

That’s correct. Database annotation is used.

4. What skills should you become accustomed with in order to create a food ordering flow for your food ordering app? Select all that apply.

  • How to create design a user flow  (CORRECT)
  • How to use audience appropriate language 
  • How to display fetched data asynchronously    (CORRECT)
  • How to fetch and store data from the network  (CORRECT)

That’s correct! Laying out the steps to be taken by the user makes design and development easier.

That’s correct! Asynchronous operations will ensure that the app does not freeze up as the user interacts with it. 

That’s correct! You’ll need to make sure the app always gets current data. 

READINESS CHECK: DOES THE HOME SCREEN ALLOW FILTERING?

1. In the Filtering the food menu exercise, which attribute from the JSON data was used to filter menu items in the menu breakdown section? 

  • name
  • category  (CORRECT)
  • price
  • title

That’s correct. The category is the correct attribute.

2. After completing the Filtering the food menu exercise, users can enter a search phrase to filter items on your app.  

  • True (CORRECT)
  • False

That’s correct. The search phrase is used with filtering. 

3. In the Filtering the food menu exercise, which Composable was used to capture search phrase input? 

  • SearchPhrase
  • SearchInput
  • TextField  (CORRECT)
  • Text

That’s correct. The TextField composable was used to capture search phrase input. 

READINESS CHECK: DID YOU COMMIT YOUR PROGRESS TO GIT?

1. Which command should you use to create a new Git branch?

  • git checkout <branch-name>
  • git checkout –b <branch-name>  (CORRECT)

That’s correct. This creates a new branch in Git.

2. Which command is used to commit the changes of a Git branch?

  • git commit “message”
  • git commit –m “message”  (CORRECT)

That’s correct. This commits the change and gives it a new message.

3. Which of the following commands is used for pushing changes to a GitHub repository?

  • push –u origin <branch-name>  (CORRECT)
  • push –u origin

That’s correct. This pushes the changes to a GitHub repository.

KNOWLEDGE CHECK: DISPLAYING THE FOOD MENU

1. What networking library did you use to read data from the remote API?

  • Glide
  • Jetpack Compose
  • Ktor Client  (CORRECT)

That’s correct. Ktor Client is the networking library used to make network calls in Kotlin.

2. What’s the right way to obtain an instance of a Ktor Client?

  • HttpClient(Ktor)
  • HttpClient(Android)  (CORRECT)
  • KtorClient(Android)

That’s correct. This is how you obtain an instance of a Ktor client.

3.  In a project that presents data from a database, what is the right way to update the user interface when new data is obtained from an API?

  • Update the state and the database with the new data.
  • Update the state. If using observeAsState, the database will update automatically.
  • Update the database with the new data. If using observeAsState, the UI will update automatically.  (CORRECT)

That’s correct. Having the database as a single source of truth simplifies the system and makes it easier to work with.

4. To filter a list of strings starting with the letter a from an existing list of strings, which command should you use?

  • list.filter { it.startsWith(“a”) }  (CORRECT)
  • list.sortedBy { it.startsWith(“a”) }
  • list.map { it.startsWith(“a”) }

That’s correct. This code will filter the list, returning a list only containing strings starting with a.

5. How do you declare a mutable Compose state of type string with a default of an empty string?

  • var state by remember { mutableStateOf(“”) }  (CORRECT)
  • var state by remember { mutableStateOf(“state”) }
  • var state = “”

That’s correct. This code will assign a mutable state to the state variable with a default value of an empty string.

MODULE QUIZ: PROJECT FUNCTIONALITY

1. You have a Student class that is defined like this:

class Student(
val name: String,
val course: String
)

Given a list of students, how do you return a list of them filtered by name containing a particular String?

  • return list.map { it.name.contains(searchPhrase, ignoreCase = true) }
  • return list.map { it.has(searchPhrase, ignoreCase = true) }
  • return list.filter { it.name.contains(searchPhrase, ignoreCase = true) }  (CORRECT)

That’s correct. This code will sort the list by the student names and return the result as a list.

2. How do you create a NavController?

  • rememberNavController() from within a Composable  (CORRECT)
  • remember { NavController() }
  • rememberNavController() from anywhere

That’s correct. This is how you create a NavController.

3. What dependencies does a NavHost constructor have?

  • A NavController and a start destination
  • A NavController and Composable destinations
  • A NavController, a start destination and Composable destinations  (CORRECT)

That’s correct. A NavHost requires all three of these to be instantiated.

4. You have a MenuItem class that is defined like this:

class MenuItem(
val title: String,
val price: Int
)

Given a list of menu items, how do you return a list of them sorted by title?

  • return list.filter { it.title }
  • return list.map { it.title }
  • return list.sortedBy { it.title }  (CORRECT)

That’s correct. This code will sort the list by the title and return the result as a list.

5. In what format was the data returned from the API in this project?

  • XML
  • JSON  (CORRECT)
  • HTTP

That’s correct. The API in this project returned a JSON object.

6. What persistence solution did you use to save the user’s details?

  • Room
  • SharedPreferences  (CORRECT)

That’s correct. SharedPreferences is the appropriate solution for persisting simple data such as the user’s details.

7. What persistence solution did you use to save the menu items?

  • SharedPreferences
  • Room  (CORRECT)

That’s correct. Room is the appropriate solution for persisting data as complex as the menu.

8. Which Composable should you use for an input field?

  • Text
  • TextField (CORRECT)
  • EditText

That’s correct. TextField is the Composable you should use if you want to add an input field.

9. NavGraph is responsible for navigating between destinations while keeping track and manipulating the back stack.

  • True
  • False (CORRECT)

That’s correct. The NavController is responsible for navigating between destinations while keeping track and manipulating the back stack.

10. How do you add click behavior to a Button Composable?

  • Button(modifier = …)
  • Button(onClick = { … })  (CORRECT)
  • Button() { onClick { … } }

That’s correct. This is the right way to add click behavior to a Button.