Search code examples
androidandroid-fragmentsgoogle-maps-android-api-2overlapping

Google Maps for Android overlapping


I have really strange problem with Google Maps Android API v2. It shows up only on Samsung Galaxy S5 (with Android 5.0 or 5.1.1) and on Sony Xperia M2 Aqua.

I have two fragments with maps and I'm switching them (using FragmentTransaction.replace) in MainActivity. When I switch from ContactFragment to MapFragment (attached as screen) the map is overlaying (this strange bar below violet action bar). In this place I have some RelativeLayout with couple of TextView's but they are not visible.

The most strange thing is that on Samsung Galaxy S5 apk signed with production certificated revealed this problem, but when I removed this apk and installed application via USB with debug certificate, problem was gone.

Screen below :

Maps overlapping


Solution

  • Problem solved !

    It seems that fault was in FragmentManager. I have Navigation Drawer in my application.

    On drawer item click I only replaced Fragment by FragmentManager : getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mFragment, mFragmentTag).commit();

    But I forgot that Fragments are not destroyed even if they are replaced by another fragment. I had to implement removing all fragments from FragmentManager before replacing FrameLayout content with another fragment :

    for(Fragment f : getSupportFragmentManager().getFragments() {
        if(f != null) {
            getSupportFragmentManager().beginTransaction().remove(f).commit();
        }
    }
    

    After adding this fix Google Maps are working well and overlapping problem is gone :)