MP2: Restaurant Activity

Created By: Geoffrey Challen
/ Updated: 2022-05-23

As we continue working on MP2, we'll work next on our new activity that displays restaurant details. This will give us a chance to do more layout, and understand a bit more about the Android Activity lifecycle.

Restaurant Activity

When we set up MP2, we created a Restaurant activity. But there are still two problems. First, how do we get it to start? Let's examine the idea of an Android Intent, and see how to use one to start the activity that we've created.

Show how to launch the restaurant activity using an Intent. Don't discuss extras yet, just get it to launch using the onClick handler, and make any necessary changes to the manifest.

Layout Revisited

Now our activity starts, but it's blank! Let's fix that by creating and using a new layout for our restaurant activity. We'll explore how to add a text box and how to populate it in onCreate.

Create a new layout, load it in onCreate using data binding, and show how to update the value of a TextField.

What's Left

We've discussed the code that you need to modify to finish the next test case. However, there is still work for you to do! Here's what's left for you to finish:

  1. You need to add an extra to your Intent named id with the value set to the unique ID of the clicked Restaurant.
  2. In onCreate on your RestaurantActivity you'll need to obtain the restaurant id and use it to retrieve the rest of the information about the restaurant, including its name and cuisine. This will probably require changes to some other part of the project. We suggest in Client.kt.
  3. Finally, you'll need to display the name and cuisine in your RestaurantActivity, which will require changes to onCreate and to your restaurant activity layout.

Let's examine what's left for you to finish to complete the next test case!

Provide an overview of the three remaining steps.

No Homework for This Lesson

As a reminder, on lessons where we focus on the machine project we will not assign a homework problem! However, the lesson will usually focus on helping you complete a particular part of the MP test suite, and so we encourage you to spend time on that in lieu of a homework problem.

Right now your goal should be to complete the next two 10-point test cases that test your new restaurant activity.

If you get stuck, find us for help on the help site or forum.

MP2 Scores

More Practice

Need more practice? Head over to the practice page.