Question

I have an android application that uses Google Maps. My first activity starts a mapview with some clickable icons. When an icon is clicked, a new activity (intent) is started with a different map. From the new map I then click the back button which takes me back to my first map. However, when I start zooming or moving around in the map, only the tiles that originally loaded will show up. How can I change this?

If you change the phone orientation the map will refresh and then it behaves normally (becuase the app restarted) so I added android:configChanges="orientation" to stop the restarting on orientation change. I added that because I don't want to reload all the markers again (uses a web service and can take some time).

I just want the tiles to load when I click "back" to the original map. Any ideas?

Was it helpful?

Solution

I ran into this problem recently as well! Check your log - you're probably getting an error along the lines of "IllegalStateException: Connection pool shut down." Also like me, the only answers you found seemed to be for people who hadn't set up their Google API key right. :-\

I eventually ran into this link. (You usually need to be signed in to your Google account to read these posts)

It appears as though there's a bug that only allows one map activity per application. Something to do with the map refreshing, I guess. I got around it by finishing each map activity after loading the new one, causing the activity to be reloaded in its entirety when the user returns to it. It's not ideal, but it's worked well for me so far.

In some more detail:

  1. Save any information about the map you want to retrieve later. Map center and map zoom first come to mind. Put it somewhere global, or pass it in with your intent.

  2. After launching the intent for the second activity, call finish() on the first one. If you want the two maps to appear to the user as the same map, then you'll want to kill the sliding transition that occurs by default when a new activity is started. Do that by calling this line immediately after finish():

overridePendingTransition(0, 0);

  1. When your second map activity needs to finish, repeat step 1 if needed and then load the first map activity back using the same method as step 2. The code from 2 would go in the onBackPressed() method of the activity, and wherever else its appropriate (maybe you have a cancel button or something).

  2. In the onCreate of the first activity, make sure you check for stuff that's been saved from the last time that activity was being viewed and modify your map appropriately.

Maybe that was verbose, but I use this site a lot and I always appreciate the answers that say too much a lot more than the ones that say too little, haha!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top