2

SupportMapFragment lags and all together has a bad performance after it's back from stack.

The promblem is strange because I use navigation graph for navigation purposes and the problem is not always present. Here are the two different scenarios:

MapFragment -> AnotherFragment (Through ActionBar menu item) -> Mapfragment

override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        onNavDestinationSelected(item!!, navController)
        return super.onOptionsItemSelected(item)
    }

In this case the MapFragment is lagging after back button pressed in AnotherFragment

MapFragment -> AnotherFragment (Through a default button) -> Mapfragment

navController.navigate(R.id.action_mapFragment_to_anotherFragment)

In this case the MapFragment acts normally.

I have tried to use navController.navigate(R.id.action_mapFragment_to_anotherFragment) in onOptionsItemSelected(item: MenuItem?) but I ended up with the same result.

I also know about this question with the same problems but under really different circumstances also the answers are not really helpful.

Umskiptingur
  • 125
  • 1
  • 10

1 Answers1

0

So the problem is not with the Mapfragment or Google's SupportMapFragment but its an Android UI bug of some kind. I was able to avoid it and I want to share the solution.

The problem itself occurred by the ActionBar's navigation, the original setup was like this. In res/menu/menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:title="@string/about"
        android:id="@+id/options_more"
        android:icon="@drawable/ic_baseline_more_vert_24px"
        android:orderInCategory="100"
        app:showAsAction="always" />
        <menu>
            <item
                android:id="@+id/anotherFragment"
                android:title="@string/another_menu_title" />

            <item
                android:id="@+id/alsoAnotherFragment"
                android:title="@string/alsoanother_menu_title" />
        </menu>
    </item>
</menu>

In this case a drop down menu appears (which contains two more items) when one clicks the menu item in the upper right corner.

When I used the layout like this the lagging occurred. After some hours of trial and error I separated the drop-down menu into two individual buttons like this:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/anotherFragment"
        android:icon="@drawable/ic_baseline_location_city_24px"
        android:title="@string/about"
        app:showAsAction="ifRoom"/>
    <item
        android:id="@+id/alsoAnotherFragment"
        android:icon="@drawable/ic_baseline_more_vert_24px"
        android:title="@string/about"
        app:showAsAction="ifRoom"/>
</menu>

So the drop-down menu had been dismissed and the problem is now gone. Everything works fine the lagging disappeared. I don't really understand what is the root of the problem but I think it has to have some kind of explanation.

Umskiptingur
  • 125
  • 1
  • 10