Setting Up Your Map

Now that you have the Maps API set up, you need to create a map. Maps are displayed, appropriately enough, in a MapView. MapView is like other views, mostly, except in one way: for it to work correctly, you have to forward all of your lifecycle events, like this:

@​O​v​e​r​r​i​d​e​
p​u​b​l​i​c​ ​v​o​i​d​ ​o​n​C​r​e​a​t​e​(​B​u​n​d​l​e​ ​s​a​v​e​d​I​n​s​t​a​n​c​e​S​t​a​t​e​)​ ​{​
 ​ ​ ​ ​s​u​p​e​r​.​o​n​C​r​e​a​t​e​(​s​a​v​e​d​I​n​s​t​a​n​c​e​S​t​a​t​e​)​;​

 ​ ​ ​ ​m​M​a​p​V​i​e​w​.​o​n​C​r​e​a​t​e​(​s​a​v​e​d​I​n​s​t​a​n​c​e​S​t​a​t​e​)​;​
}​

This is a huge pain in the neck. It is far easier to let the SDK do that work for you instead by using a MapFragment or, if you are using support library fragments, SupportMapFragment ...

Get Android Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.