I have a GridMarkerClusterer with some Marker in it representing shared bike stations. I want those markers have a custom MarkerInfoWindow (bubble) with a click listener so that when the user clicks on the bubble, a new intent is launched.
Thus far, I'm OK.
Now I want to put extra data (station information corresponding to the marker) to that intent.
What I actually did is to add a constructor in my StationMarkerInfoWindow which takes a Station in parameter. I then add this parameter to the intent with putExtra() in my OnClickListener.
That's working but what is wrong is that I need to create a new StationMarkerInfoWindow for each marker instead of using the same object, and if I have more than 1000 markers to display, the activity takes up to 10 seconds to be created on my device (~1 second if I use the same StationMarkerInfoWindow object for each marker).
The question is: how should I add those data to the intent?
Here are the relevant parts of the code:
public class MapActivity extends Activity {
private BikeNetwork bikeNetwork;
private ArrayList<Station> stations;
private MapView map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
// ...
stations = bikeNetwork.getStations();
map = (MapView) findViewById(R.id.mapView);
GridMarkerClusterer stationsMarkers = new GridMarkerClusterer(this);
Drawable clusterIconD = getResources().getDrawable(R.drawable.marker_cluster);
Bitmap clusterIcon = ((BitmapDrawable) clusterIconD).getBitmap();
map.getOverlays().add(stationsMarkers);
stationsMarkers.setIcon(clusterIcon);
stationsMarkers.setGridSize(100);
for (final Station station : stations) {
stationsMarkers.add(createStationMarker(station));
}
// ...
}
private Marker createStationMarker(Station station) {
Marker marker = new Marker(map);
marker.setInfoWindow(new StationMarkerInfoWindow(
R.layout.bonuspack_bubble, map, station)); // this seems wrong
marker.setInfoWindow(stationMarkerInfoWindow);
marker.setPosition(stationLocation);
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER);
marker.setIcon(getResources().getDrawable(R.drawable.ic_bike));
marker.setTitle(station.getName());
marker.setSnippet(String.valueOf(station.getFreeBikes())); // free bikes
marker.setSubDescription(String.valueOf(station.getEmptySlots())); // empty slots
return marker;
}
private class StationMarkerInfoWindow extends MarkerInfoWindow {
Station station;
public StationMarkerInfoWindow(int layoutResId, final MapView mapView, final Station station) {
super(layoutResId, mapView);
this.station = station;
}
#Override
public void onOpen(Object item) {
super.onOpen(item);
closeAllInfoWindowsOn(map);
LinearLayout layout = (LinearLayout) getView().findViewById(R.id.map_bubble_layout);
layout.setClickable(true);
layout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MapActivity.this, StationActivity.class);
intent.putExtra("station", station);
startActivity(intent);
}
});
}
}
}
I would suggest to set the Station as the "related object" of its Marker:
marker.setRelatedObject(station);
You can then retrieve this related object in StationMarkerInfoWindow#onOpen:
Marker marker = (Marker)item;
selectedStation = (Station)marker.getRelatedObject();
Similar implementation can be found here.
Then you can share the same StationMarkerInfoWindow.
Related
Without using the ClusterManager, I use HashMap to put the Marker and ID into the HashMap, and get the ID in the OnMarkClick method and get the data from database. It's works
markers.put(addNewMarker(geoPoint), objectId);
private Marker addNewMarker(ParseGeoPoint parseGeoPoint) {
double latitude = parseGeoPoint.getLatitude();
double longitude = parseGeoPoint.getLongitude();
return googleMap.addMarker(new MarkerOptions().position(
new LatLng(latitude, longitude)));
}
#Override
public boolean onMarkerClick(Marker marker) {
String objectId = markers.get(marker);
if (null == objectId) {
return false;
}
getMemoryBriefInfo(objectId);
return true;
}
But now I need to use the ClusterManager to cluster multiple markers into number.
The problems is It seems there is no way to implement this, in the demo of Google, it just add the Items into the Cluster.
There is a OnMarkerClick method in the ClusterManager class, but I don't how to Override this and set with my own unique ID.
there is a global solution for you that help to add title, snippet and icon so you can get what you want.
Modify your ClusterItem Object and add 3 variables :
public class MyItem implements ClusterItem {
private final LatLng mPosition;
BitmapDescriptor icon;
String title;
String snippet;
public MyItem(BitmapDescriptor ic,Double lat , Double lng,String tit ,String sni)
{
mPosition = new LatLng(lat,lng);
icon = ic;
title = tit;
snippet = sni;
}
And after you create your costume render :
public class OwnRendring extends DefaultClusterRenderer<MyItem> {
public OwnRendring(Context context, GoogleMap map,
ClusterManager<MyItem> clusterManager) {
super(context, map, clusterManager);
}
protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {
markerOptions.icon(item.getIcon());
markerOptions.snippet(item.getSnippet());
markerOptions.title(item.getTitle());
super.onBeforeClusterItemRendered(item, markerOptions);
}
}
After that just put this line in your SetUpCluster() function before addItems():
mClusterManager.setRenderer(new OwnRendring(getApplicationContext(),mMap,mClusterManager));
I'm currently developing an Android app that have to receive GPS positions from other devices every minutes, and display them on a map.
I'm using the GoogleMaps Api V2,
What i'd like to do, is to refresh the position marker very time a new position is received. (I don't want to refresh the whole map)
For the moment, I've added a button in the menu that enables me to refresh the entire map.
To detail to structure, I have a service that run MQTT, and every time a position is received, I add it into an Hashmap, that represents my map data source.
This HashMap is a Singleton that extends Observable.
Moreover, my fragment that display the my implements Observer.
Code from my Fragment that implements Observer
public void update(Observable observable, final Object object)
{
if (observable instanceof ListPositions && object != null)
{
Position p = (Position) object;
LatLng position = new LatLng(p.getLatitude(), p.getLongitude());
// Where i'd like to move the markers
}
else
{
// Where i'd like to remove the marker from the map
}
}
Code From my Singleton List of position
public class ListPositions extends Observable{
private HashMap<String,Position> mapPosition;
private ListPositions()
{
mapPosition = new HashMap<String, Position>();
VehicleMapFragment mapFragmentObserver = new VehicleMapFragment();
this.addObserver(mapFragmentObserver);
}
private static ListPositions INSTANCE = null;
public static synchronized ListPositions getInstance()
{
if (INSTANCE == null)
{ INSTANCE = new ListPositions();
}
return INSTANCE;
}
public int getNumberOfPosition()
{
return mapPosition.size();
}
public void addPosition(String key, Position p){
mapPosition.put(key,p);
setChanged();
notifyObservers(p);
}
public void removePosition(String key){
mapPosition.remove(key);
setChanged();
notifyObservers();
}
Code From myService that runs MQTT
public void onPositionMessageReceived(MqttMessage message, String source)
{
Gson gson = new Gson();
String s = gson.toJson(message.toString());
String jsonPosition = gson.toJson(message.toString());
jsonPosition = formatMessage(jsonPosition);
Position p = gson.fromJson(jsonPosition, Position.class);
ListPositions.getInstance().addPosition(source, p);
}
Can someone know how to move each markers individually without refreshing the whole map, in my update function from my Observer Fragment?
May I use a Handler to update the Map, from an other thread to modify the Main UI Thread ?
Many thanks
EDIT :
Because the first methode given by AniV didn't work for me, I've tried with an Asyntask that runs when my Observer get a notification from the Observable List.
Code from the Observer Fragment :
public void update(Observable observable, final Object object)
{
if (observable instanceof ListPositions && object != null)
{
Position p = (Position) object;
position = new LatLng(p.getLatitude(), p.getLongitude());
options = new MarkerOptions().position(position).title("TEST").snippet("TEST");
PositionUpdate positionUpdaterTask = new PositionUpdate(myGoogleMap, options, position);
positionUpdaterTask.execute();
}
}
Code from the AsyncTask :
public class PositionUpdate extends AsyncTask<Void, Void, Void>{
private GoogleMap myGoogleMap;
private MarkerOptions options;
private LatLng positionToAdd;
public PositionUpdate(GoogleMap googleMap, MarkerOptions options, LatLng position)
{
this.myGoogleMap = googleMap;
this.options = options;
this.positionToAdd = position;
}
#Override
protected Void doInBackground(Void...voids)
{
return null;
}
#Override
protected void onPostExecute(Void aVoid)
{
if (myGoogleMap != null)
{
myGoogleMap.addMarker(options.position(positionToAdd));
Log.i(ConstElisa.LOG_ELISA, "MARKER ADDED");
}
else
{
Log.e(ConstElisa.LOG_ELISA, "ERROR ADDING THE MARKER");
}
super.onPostExecute(aVoid);
}
However, in this case, myGoogleMap variable is always null, so the marker is never added to the Google Map.
Does someone have an idea why this variable is null ?
I finally succeeded in doing that thing by using the AsyncTask.
In my EDIT, I said that I had some trouble with the null instance of my Google Maps object.
This was caused by my Singleton Observable. Indeed, in the constructor, I used
VehicleMapFragment mapFragmentObserver = new VehicleMapFragment();
this.addObserver(mapFragmentObserver);
This code sample recreated another instance of my Fragment, and that the reason why ii had Null objects.
To correct this problem, I simply used :
ListPositions.getInstance().addObserver(this);
in my Fragment Observer.
So if you want to update a marker position without refreshing the whole map,
you can use the Observer/Observable Pattern, and use an Asynctask to update the marker position.
You have two options here:
Either update the marker position programatically using setPosition() method.
Marker marker = googleMap.addMarker(new MarkerOptions().position(entry.getValue()).title(entry.getKey()));
Use this object to change its position:
marker.setPosition(new LatLng(5, 5));
OR as you said, Make use of Handlers:
Handler locationHandler;
final static long REFRESH = 10 * 1000;
final static int SUBJECT = 0;
private GoogleMap mMap;
private Marker myMarker = null;
and onCreate()
locationHandler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == SUBJECT) {
updateMarker();
this.sendEmptyMessageDelayed(SUBJECT, REFRESH);
}
}
};
Handler option is better in cases where you have to update the position at a specific time interval.
I have something like this. I receive a list of devices every 5 minutes to update locations of the map.
What do you think about this
private HashMap<String, Marker> mMarkers = new HashMap<>();
private void drawDevicesOnMap() {
if (isMapReady) {
for (Device device : mDeviceList) {
List<com.model.Location> locationList = device.getLocations();
if (locationList != null && !locationList.isEmpty()) {
if (mMarkers.containsKey(device.getId())) { //update
Marker m = mMarkers.get(device.getId());
m.setPosition(device.getLocations().get(0).getCoordinates().getLatLng());
mMarkers.put(device.getId(), m);
} else { //add
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(locationList.get(0).getCoordinates().getLatLng());
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(device.getHue()));
markerOptions.title(device.getNickname());
Marker marker = mMap.addMarker(markerOptions);
mMarkers.put(device.getId(), marker);
}
}
}
}
}
if the marker for a device with x id is found in the HashMap, you update its location.
I have two activities one that send coordinates and one that recieves and drawing them.
I need that both of them will show GoogleMap... in the first activity i can see google map right away but then when i call to the second activity from BroadcastReceiver i just see blank white screen.
Thats my Second activity code:
public class NewActivity extends FragmentActivity {
GoogleMap googleMap;
String message;
String number;
double[] d = new double[4];
ArrayList<LatLng> points= new ArrayList<LatLng>() ;
#Override
public void onStart() {
super.onStart();
final LocalBroadcastManager localBroadcastManager =
LocalBroadcastManager.getInstance(this);
final IntentFilter localFilter = new IntentFilter();
localBroadcastManager.registerReceiver(localBroadcastReceiver, localFilter);
}
#Override
public void onStop() {
super.onStop();
final LocalBroadcastManager localBroadcastManager =
LocalBroadcastManager.getInstance(this);
// Make sure to unregister!!
localBroadcastManager.unregisterReceiver(localBroadcastReceiver);
}
BroadcastReceiver localBroadcastReceiver = new BroadcastReceiver()
{
#Override
public void onReceive(Context context, Intent intent)
{
setContentView(R.layout.ye);
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = fm.getMap();
googleMap.setMyLocationEnabled(true);
message=intent.getStringExtra("message");
number=intent.getStringExtra("number");
int p=0;
Matcher m = Pattern.compile("(?!=\\d\\.\\d\\.)([\\d.]+)").matcher(message);
while(m.find())
{
double k = Double.parseDouble(m.group(1));
d[p]=k;
p++;
}
PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.color(Color.BLUE);
// Setting the width of the polyline
polylineOptions.width(6);
// Adding the taped point to the ArrayList
LatLng coordlocation = new LatLng(d[0], d[1]);
points.add(coordlocation);
LatLng coordlocation2 = new LatLng(d[2], d[3]);
points.add(coordlocation2);
// Setting points of polyline
polylineOptions.addAll(points);
googleMap.addPolyline(polylineOptions);
}
};
}
Note : I didnt registered the localBroadcastReceiver in the manifest file since i dont know if its neccessary.
I solved it by adding this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ye);
}
In order to detect map movements and gestures and use the lazy loading support for my map items I'm trying to work with this library: http://code.google.com/p/mapview-overlay-manager/.
I've setup a map attached the overlayManager and the events are coming through just fine. I can throw a toast from the listener just fine. When I get Application context it is not null.
I'm stuck trying to launch an intent from the ManagedOverlay class. Specifically in the onDoubleTap method below I'm trying to launch an intent and I get this error message:
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
I think I generally understand that I need to call back to the MapActivity subclass and have it launch the intent or I need to do something with the context differently. I'm having trouble ironing out the specifics however. Any assistance appreciated.
public class SiteMapRev2 extends MapActivity {
private MapView mapView;
private OverlayManager overlayManager;
private MapController mapController;
private MyLocationOverlay userLocationOverlay;
private ArrayList<SiteSummary> sitesRoster = null;
private Drawable siteIcon;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
overlayManager = new OverlayManager(this, mapView);
sitesRoster = new ArrayList<SiteSummary>();
userLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(userLocationOverlay);
mapController = mapView.getController();
mapController.setZoom(14);
siteIcon = this.getResources().getDrawable(R.drawable.marker2);
}
#Override
public void onStart() {
super.onStart();
Drawable defaultmarker = getResources().getDrawable(R.drawable.marker2);
ManagedOverlay managedOverlay = overlayManager.createOverlay("sites", defaultmarker);
managedOverlay.setOnOverlayGestureListener(new ManagedOverlayGestureDetector.OnOverlayGestureListener(){
public boolean onDoubleTap(MotionEvent arg0, ManagedOverlay arg1,
GeoPoint arg2, ManagedOverlayItem arg3) {
if (arg3 == null) {
return false;
}
else {
**SiteOverlayItem thisItem = (SiteOverlayItem) arg3;
String siteIDAsString = Integer.toString(thisItem.getSiteID());
Context c = getApplicationContext();
Intent showSiteDetails = new Intent(c,SiteDetailActivity.class);
Log.d(toString(), "intent = " + showSiteDetails.toString());
showSiteDetails.setData(Uri.parse(siteIDAsString));
c.startActivity(showSiteDetails);
return true;**
}
}
Instead of getting the application context, I would do this:
SiteMapRev2.this.startActivity(showSiteDetails);
which starts the activity from your map activity as you normally would.
Set this Flag to your intent, Logcat is too smart, try to understand what is says to you ;)
showSiteDetails.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
I have a strange problem and really dont know where to start debug. I have 2 activities one that holds a googlemap view and when the user taps the marker on the view i start a new activity that shows a detailed description of that marker. If i hit the back buttton on my detalied activity it returns me to the map activity, so far so good. BUT if i tap a new (or same) marker i get to the detailed activity again (all fine) if i try to hit the back button again i get returned to the detailed activity that i tapped the very first time, and i can hit back once more and finaly get to the map activity again.
if i keep debugggin i can get up to 10 activities that i have to push back on before i finaly get to the map activity again
what the heck is going on ? does android forget history or something due to i implement the map activity instead of activity ?
anyone that has an idea of where to start looking for the problem
Here comes a lot of code:
map activity
public class SpotGuideMapActivity extends MapActivity
{
protected MapView mapView;
protected MapController mapController;
protected List<Overlay> mapOverlays;
protected Drawable overlayIcon;
protected SpotGuideOverlay spotsOverlay;
protected MyLocationOverlay myLocOverlay;
protected ArrayList<SpotItem> _spots;
protected Button ButtonHome;
protected Button ButtonPreferences;
protected Intent _intent = null;
private SpotGuideDbAdapter _spotDbAdapter;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.spot_map);
_intent = getIntent();
ActivityHelper.createInstance(this).setTopBarTitle("Spot kortet");
ButtonPreferences = (Button)findViewById(R.id.btnPreferences);
ButtonPreferences.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
startActivity(new Intent(getApplicationContext(), GlobalPreferencesActivity.class));
overridePendingTransition(R.anim.slide_right_in,R.anim.slide_right_out);
}
});
ButtonHome = (Button)findViewById(R.id.btnHome);
ButtonHome.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
startActivity(new Intent(getApplicationContext(), HomeActivity.class));
overridePendingTransition(R.anim.slide_left_in,R.anim.slide_left_out);
}
});
//mapView.invalidate();
}
#Override
protected void onResume()
{
super.onResume();
if(_intent.hasExtra("latitude") && _intent.hasExtra("longitude"))
{
String latitude = _intent.getStringExtra("latitude");
String longitude = _intent.getStringExtra("longitude");
double lat = Double.parseDouble(latitude);
double lon = Double.parseDouble(longitude);
GeoPoint point = new GeoPoint((int)(lat * 1E6) , (int)(lon * 1E6));
initMapView(point);
}
else
{
initMapView(null);
}
drawSpotMarkers();
}
#Override
protected void onPause()
{
super.onPause();
myLocOverlay.disableCompass();
myLocOverlay.disableMyLocation();
}
protected void initMapView(GeoPoint centerPoint)
{
mapView = (MapView)findViewById(R.id.spotGuideMap);
mapView.setBuiltInZoomControls(true);
mapController = mapView.getController();
//current location overlayer
myLocOverlay = new MyLocationOverlay(this, mapView);
myLocOverlay.enableCompass();
myLocOverlay.enableMyLocation();
mapView.getOverlays().add(myLocOverlay);
GeoPoint point = null;
if(centerPoint == null)
{
point = myLocOverlay.getMyLocation();
if(point == null)
{
point = new GeoPoint((int)(55.5616508394963 * 1E6) , (int)(12.563638687133789 * 1E6));
}
}
else
{
point = centerPoint;
}
//get the last know location, be fresh so use last fix
//Location location = myLocOverlay.getLastFix();
//GeoPoint locationPoint;
//locationPoint = new GeoPoint((int)(location.getLatitude() * 1E6) , (int)(location.getLongitude() * 1E6));
mapController.animateTo(point);
mapController.setZoom(10);
}
protected void drawSpotMarkers()
{
mapOverlays = mapView.getOverlays();
overlayIcon = getResources().getDrawable(R.drawable.map_icon_pink);
spotsOverlay = new SpotGuideOverlay(overlayIcon, this);
_spotDbAdapter = new SpotGuideDbAdapter(this).Open();
_spots = _spotDbAdapter.getAllSpots();
for (SpotItem spot : _spots)
{
double lat = Double.parseDouble(spot.getLatitude());
double lon = Double.parseDouble(spot.getLongitude());
GeoPoint point = new GeoPoint((int)(lat * 1E6) , (int)(lon * 1E6));
OverlayItem overlayitem = new OverlayItem(point, spot.getSpotTitle(), Integer.toString(spot.getId()));
spotsOverlay.addOverlay(overlayitem);
}
mapOverlays.add(spotsOverlay);
}
#Override
protected boolean isRouteDisplayed()
{
return false;
}
}
detailed activity
public class SpotGuideDescriptionActivity extends BaseActivity
{
private SpotGuideDbAdapter _spotDbAdapter;
protected Button ButtonHome;
protected Button ButtonPreferences;
protected Button ButtonBacktoMap;
protected TextView tvSpotTitle;
protected TextView tvSpotType;
protected TextView tvWindDirection;
protected TextView tvContent;
protected Intent _intent = null;
protected SpotItem item;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.spot_description);
_intent = getIntent();
this.getActivityHelper().setTopBarTitle("Spot beskrivelse");
tvSpotTitle = (TextView)findViewById(R.id.spotDescTitle);
tvSpotType = (TextView)findViewById(R.id.spotDescType);
tvWindDirection = (TextView)findViewById(R.id.spotDescWind);
tvContent = (TextView)findViewById(R.id.spotDescContent);
ButtonBacktoMap = (Button)findViewById(R.id.btnBackToMap);
ButtonBacktoMap.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent = new Intent(getApplicationContext(), SpotGuideMapActivity.class);
intent.putExtra("latitude", item.getLatitude());
intent.putExtra("longitude", item.getLongitude());
startActivity(intent);
overridePendingTransition(R.anim.slide_left_in,R.anim.slide_left_out);
}
});
ButtonPreferences = (Button)findViewById(R.id.btnPreferences);
ButtonPreferences.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
startActivity(new Intent(getApplicationContext(), GlobalPreferencesActivity.class));
overridePendingTransition(R.anim.slide_right_in,R.anim.slide_right_out);
}
});
ButtonHome = (Button)findViewById(R.id.btnHome);
ButtonHome.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
startActivity(new Intent(getApplicationContext(), HomeActivity.class));
overridePendingTransition(R.anim.slide_left_in,R.anim.slide_left_out);
}
});
init();
}
private void init()
{
if(_intent.hasExtra("spot_id"))
{
int id = _intent.getIntExtra("spot_id", 0);
_spotDbAdapter = new SpotGuideDbAdapter(this).Open();
item = _spotDbAdapter.getSpot(id);
tvSpotTitle.setText(item.getSpotTitle());
tvSpotType.setText(item.getSpotType());
tvWindDirection.setText(item.getWindDirections());
tvContent.setText(item.getSpotDescription());
}
}
}
And i init the tap in my OverlayItem like this
public boolean onTap(int index)
{
OverlayItem item = mOverlays.get(index);
Intent descIntent = new Intent(currentContext.getApplicationContext(), SpotGuideDescriptionActivity.class);
descIntent.putExtra("spot_id", item.getSnippet());
currentContext.startActivity(descIntent);
return false;
}
it is not the BackToMap button that i use, it is the back button on all phones
I haven't worked with maps, so I may be off my rocker. But the fact that you are calling initMapView() in OnResume() might be creating two markers one on top of the other (and again, every time you go back). So when you think you are taping on one marker, you are actually taping on multiple markers.
That's just off the top of my head, and can be total malarkey.
A quick solution would be to #Override onBackPressed() to open the map activity back up. This might lead to you having to do it to navigate the entire app, though. If it's just that map page and the overlay with more info, you can easily just have this on the page that is duplicating:
#Override
onBackPressed(){
Intent i = new Intent(this, Activity.class);
startActivity(i);
}
then on the activity with the mapview
#Override
onBackPressed(){
moveTaskToBack(true);
}