views:

66

answers:

2

I'm developing an application that shows a path on a map, determined by a KML file. Specifically, in the MapActivity that is starting the map:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    Uri uri = Uri.parse("geo:0,0?q=http://urltokml");
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri);
    mapIntent.setData(uri);

    startActivity(Intent.createChooser(mapIntent, kmlFile));
    finish();
}

The map loads fine and after a few seconds the path described by the KML shows up. The problem is, when I press the "Back" button, it does not return to the previous screen but instead just hides the KML overlay. If the "Back" button is pressed again, it will return to the previous screen.

Any ideas of how to solve this?

A: 

Depends on what version of the API you are using... in the later versions there is an "OnBackPressed" method that you can override in your activity to adjust the back behavior.

Mayra
A: 

It's because you're starting your activity and loading a blank map

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

and then creating an Intent to launch a NEW map with the kml file

    Uri uri = Uri.parse("geo:0,0?q=http://urltokml");
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri);
    mapIntent.setData(uri);

    startActivity(Intent.createChooser(mapIntent, kmlFile));
    finish();
}

So what's happening when you hit back is that it's leaving the second map (with the kml file) and returning to the first map (that is blank).

CaseyB
I'm now calling Uri uri = Uri.parse("geo:0,0?q=http://urlhere"); Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri); mapIntent.setData(uri); startActivity(Intent.createChooser(mapIntent, "Title"));from another activity (a non-mapping one) but the back button has the same effect.
aaronr
At that point it's the built in Maps program, I don't know how it handles the request.
CaseyB