Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 安卓地图后退按钮_Java_Android_Google Maps_Kml - Fatal编程技术网

Java 安卓地图后退按钮

Java 安卓地图后退按钮,java,android,google-maps,kml,Java,Android,Google Maps,Kml,我正在开发一个在地图上显示路径的应用程序,该路径由KML文件确定。具体而言,在启动地图的地图活动中: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MapView mapView = (MapView) findViewById(R.id.mapview); mapView.se

我正在开发一个在地图上显示路径的应用程序,该路径由KML文件确定。具体而言,在启动地图的地图活动中:

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();
}
地图加载良好,几秒钟后,KML描述的路径显示出来。问题是,当我按下“后退”按钮时,它不会返回到上一个屏幕,而只是隐藏KML覆盖。如果再次按下“后退”按钮,它将返回上一屏幕


关于如何解决这个问题有什么想法吗?

取决于您使用的API版本。。。在以后的版本中,有一个“OnBackPressed”方法,您可以在活动中重写该方法以调整后退行为。

这是因为您正在启动活动并加载空白映射

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);
然后创建使用kml文件启动新的映射的意图

    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();
}

因此,当您回击时,它将离开第二个映射(带有kml文件)并返回到第一个映射(为空)。

我现在调用Uri-Uri=Uri.parse(“geo:0,0?q=);Intent-mapIntent=new-Intent(Intent.ACTION\u-VIEW,Uri);mapIntent.setData(Uri);startActivity(Intent.createChooser(mapIntent,”来自另一个活动(非映射活动),但后退按钮具有相同的效果。此时它是内置的映射程序,我不知道它如何处理请求。