簡體   English   中英

即使用戶導航到另一個無地圖片段,Google Maps API也會運行請求

[英]Google Maps API running requests even if user navigates to another mapless fragment

在我的應用程序中,我有一個帶有Google Map API V2的屏幕(片段)。如果打開此屏幕,然后打開導航抽屜,然后單擊並轉到應用程序中的其他位置,在接下來的2-3秒鍾內,我可以看到該地圖繼續在后台執行一些請求。

如何阻止它們在片段的onPause / onDestroy中運行?

在此處輸入圖片說明

這是地圖代碼的一部分:

mapFragment = (SupportMapFragment)     getActivity().getSupportFragmentManager().findFragmentById(R.id.map);
    googleMap = mapFragment.getMap();
    MapsInitializer.initialize(getActivity());
    googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {
        public boolean onMarkerClick(Marker arg0) {

            cameraUpdateAction = CameraUpdateAction.CAMERA_ANIMATE;
            return false;

        }
    });

    googleMap.getUiSettings().setZoomControlsEnabled(false);
    googleMap.setMyLocationEnabled(true);
    googleMap.getUiSettings().setMyLocationButtonEnabled(false);
    googleMap.setOnCameraChangeListener(onCameraChangeListener());

MapFragment文檔中 ,它指出Any objects obtained from the GoogleMap is associated with the view. It's important to not hold on to objects (eg Marker) beyond the view's life. Otherwise it will cause a memory leak as the view cannot be released. Any objects obtained from the GoogleMap is associated with the view. It's important to not hold on to objects (eg Marker) beyond the view's life. Otherwise it will cause a memory leak as the view cannot be released.

你可以嘗試調用清除()的GoogleMap的方法MapFragment的的onPause()/的onDestroy()方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM