Let's continue our work on the machine project! In this lesson we'll first wrap up some leftover networking work in our API client. Then we'll shift our attention to the remaining steps needed to finish this feature: support for adding new favorite places in our app's user interface.
At this point we've added support to our server for receiving
POST requests from clients.
But we still haven't added that capability to the API client used by our app.
So let's wrap this up before we shift our focus to our new activity.
When you're done, you should be able to pass
Note that this method is quite similar to code that we've provided, and most of the hard work is already done in the server.
So we're not going to provide too much detailed guidance here.
Now that we have support for adding new favorite places both in our backend server and in our API client, we need to address one of the more interesting parts of this task: interaction with the user!
At present our app allows users to browse the map, view favorite places, and click on them to see more details. What do we need to allow them to add their favorite place?
places.csv: a unique ID, a name, and a description.
There are multiple ways that you could initiate this dialog and collect the required information. Here's how we're going to approach it:
Today we'll work on adding support for long presses to our current map view.
We'll also discuss how to launch a new activity in Android, and how to pass that activity data that it might need—in our case, the latitude and longitude.
That will allow us to pass
First, let's discuss how to add the ability to handle long press events on our existing map.
This is somewhat non-obvious and requires understanding of
osmdroid, the mapping library we're using.
So we'll step through it together in the video below.
To continue, we need to discuss the process of launching a new activity in Android—meaning moving from one screen in the app to another.
We do this by using an
Intent, which we'll demonstrate in the walkthrough below.
We also need to make some changes to our Android manifest before this will work properly.
At this point we're nearly done with our third MP2 test case!
For that test case to pass, a long press on the map should launch the
That activity can be empty, but the
Intent used to launch it must contain the
longitude location of the long press on the map, as extras with the keys
Note that you should add these values as
Strings, not as
Doubles, since this makes it easier to detect missing values.
String?s can be
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
postFavoritePlacemethod on your API client and pass
test2_LongPressLaunchesActivity, specifically adding information to the
Need more practice? Head over to the practice page.