【问题标题】:Map Activity won't stop on backpress地图活动不会在后台停止
【发布时间】:2017-12-13 07:33:25
【问题描述】:

我有一个地点列表。当用户点击每个项目时,另一个Activity 会显示放置在地图活动上的项目。我在单击项目时发送带有putExtra 的 LatLng。

一切正常,但我的问题是当用户从地图活动中回退时,地图再次显示,某种刷新(要退出地图活动,用户必须按两次!)。

在后按 killfinish() 或其他杀戮页面将不起作用!

第一个活动

lv = getListView();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  @Override
  public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
    Intent intent = new Intent(getApplicationContext(),BimarestanMAP.class);
    switch(position) {
      case 0 :
        intent.putExtra("name", str1);
        intent.putExtra("lat", bim1a);
        intent.putExtra("lan", bim1l);
        startActivity(intent);
        break;
    }

地图活动:

initilizeMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(true);
googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setRotateGesturesEnabled(true);
googleMap.getUiSettings().setZoomGesturesEnabled(true);
Bundle bundle = getIntent().getExtras();
str1 = bundle.getString("name");
final double lat = bundle.getDouble("lat");
final double lan = bundle.getDouble("lan");

Marker marker = googleMap.addMarker(new MarkerOptions()
  .position(new LatLng(lat, lan))
  .title(str1)
  .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
marker.showInfoWindow();
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lan), 15));

@Override
protected void onResume () {
  super.onResume();
  initilizeMap();
}

private void initilizeMap() {
  if (googleMap == null) {
    googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
    // check if map is created successfully or not
    if (googleMap == null) {
      Toast.makeText(getApplicationContext(), "sorry no map!", Toast.LENGTH_SHORT).show();
    }
  }
}
}

【问题讨论】:

标签: android android-maps-v2


【解决方案1】:

已解决,谢谢; 添加: intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

在项目意图中;

【讨论】:

  • 不要在别人给出正确答案的情况下发布自己的答案。接受它作为正确答案。
【解决方案2】:

添加以下意图标志

  Intent intent = new Intent(Activity1.this, Activity2.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    startActivity(intent);
    finish();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多