简体   繁体   English

Android:恢复后MapView没有响应

[英]Android: MapView not responding after Resume

I have a strange problem with a com.google.android.gms.maps.MapView. com.google.android.gms.maps.MapView有一个奇怪的问题。 To check if my App crashes after the garbage collector is doing his job i force my HTC One (4.2.2) to allow only 1 running app in background. 为了检查垃圾收集器执行我的应用程序后是否崩溃,我强制我的HTC One(4.2.2)在后台仅允许运行1个应用程序。 If I leave my app(home button) while showing a MapView, start any other app and resume to my app, my MapView is still showing up...but I can not move or zoom the map, it's not responding at all. 如果我在显示MapView时离开我的应用程序(主页按钮),启动任何其他应用程序并恢复到我的应用程序,则我的MapView仍在显示...但是我无法移动或缩放地图,根本没有响应。 Other activities are working fine. 其他活动都正常。 I really have no clue where the problem might be. 我真的不知道问题可能在哪里。

Hope that someone can help me out? 希望有人可以帮助我吗?

Here is the sourcecode of my fragment that shows the MapView public class FragmentAdvertlistMap extends Fragment { 这是我的片段的源代码,该片段显示了MapView公共类FragmentAdvertlistMap扩展了Fragment {

com.google.android.gms.maps.MapView m;
GoogleMap mMap;
ArrayList<Advert> ads;
HashMap<Marker, String> myMarker;
public final LatLngBounds.Builder builder= new LatLngBounds.Builder();

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
        Bundle savedInstanceState) {
     try {
        MapsInitializer.initialize(getActivity());
    } catch (GooglePlayServicesNotAvailableException e) {
        // TODO handle this situation
    }
    View inflatedView = inflater.inflate(R.layout.activity_advert_tab2, container, false);
    m = (com.google.android.gms.maps.MapView)inflatedView.findViewById(R.id.map_tab);
    m.onCreate(savedInstanceState);

    myMarker = new HashMap<Marker, String>();
    ads= AdvertListActivity.getAdverts();
    setUpMapIfNeeded(inflatedView);
    mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

        @Override
        public void onInfoWindowClick(Marker arg0) {
            Intent myIntent = new Intent(getActivity(), AdvertLocationActivity.class);

            Advert putadvert = DefaultApplication.dbc.getAdvertForAdvertID(Integer.parseInt(myMarker.get(arg0)));

            myIntent.putExtra("advert", putadvert);
            startActivity(myIntent);

        }
    });
    return inflatedView;
}


private void setUpMapIfNeeded(View inflatedView) {
    if (mMap == null) {
        mMap = ((com.google.android.gms.maps.MapView) inflatedView.findViewById(R.id.map_tab)).getMap();
        if (mMap != null) {
            this.initMarker();
        }
    }
}

public void initMarker(){
    for(int i=0;i<ads.size();i++){
        Advert tempAd = ads.get(i);
        LatLng tlalo =  new LatLng(tempAd.mainLocation.latitude,tempAd.mainLocation.longitude);

        builder.include(tlalo);

        String address = "";
        if(tempAd.mainLocation.contact_street != null){
            address = address + tempAd.mainLocation.contact_street;
        }
        if(tempAd.mainLocation.contact_street_number != null){
            address = address + " " + tempAd.mainLocation.contact_street_number;
        }
        Marker marker = mMap.addMarker(new MarkerOptions()
        .position(tlalo)
        .anchor(0.5f, 0.5f)
        .title(tempAd.name)
        .snippet(address)
        .icon(BitmapDescriptorFactory.fromResource(R.drawable.androidpin)));

        myMarker.put(marker,String.valueOf(tempAd.myid));
    }



mMap.setOnCameraChangeListener(new OnCameraChangeListener() {
    @Override
    public void onCameraChange(CameraPosition arg0) {
        mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 100));
        mMap.setOnCameraChangeListener(null);
    }

});
}


@Override
public void onResume() {
    super.onResume();
    m.onResume();
}

@Override
public void onPause() {
    super.onPause();
    m.onPause();
}

@Override
public void onDestroy() {
    super.onDestroy();
    m.onDestroy();
}

@Override
public void onLowMemory() {
    super.onLowMemory();
    m.onLowMemory();
}


}

try add this in onCreateView() 尝试在onCreateView()中添加它

container.removeAllViews();

I found it in another similar question to yours but I lost the original link of the answer... 我在另一个与您的问题类似的问题中找到了它,但是我丢失了答案的原始链接...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM