4

I have a problem with my Android app. The activity has an options menu.

The menu looks like this:

<menu
    xmlns:android="http://schemas.android.com/apk/res/android">
  <item
    android:title="@string/tx_1" 
    android:id="@+id/menu_1"        
    >
    <menu>
      <group android:checkableBehavior="single">
        <item 
          android:title="@string/tx_2" 
          android:id="@+id/menu_2"      
          />
        <item 
          android:title="@string/tx_3" 
          android:id="@+id/menu_3"      
          />
      </group>          
      <item 
        android:title="@string/tx_4" 
        android:id="@+id/menu_4"  
        android:checkable="true"    
        />
      </menu>
    </item>
  <item
    android:title="@string/tx_5"
    android:id="@+id/menu_5"
    />      
</menu>

So there is a SubMenu when you click on the first item. It looks like a dialog, but I cannot find a way to get a reference to this dialog. When I rotate the device, there is a leaked window-error. So, it seems like Android is not closing the SubMenu. Is there a way to prevent this error? The SubMenu disappears, of course, after recreating, triggered by the orientation change. I can reopen the options menu, but not the SubMenu. Is it possible to simulate a click on the first menu item?

Thanks in advance!

And by the way, I don't want to bypass the rotation by changing the manifest.

hicks
  • 131
  • 6
  • Did you ever find a solution to this? I'm struggling with this, too. I've tried grabbing a reference to the SubMenu during onMenuItemSelected and calling subMenu.close() during the activity onPause but for some reason that doesn't resolve the issue. – Robert Nekic Mar 13 '12 at 16:08
  • I have exactly the same problem. I'd pay to find a fix. – Rémi Jul 22 '12 at 19:53

1 Answers1

0

Simple solution would be to prevent destorying Activity instance when App Orientation changes. You can do so by declaring following in your Manifest:

<activity android:configChanges="orientation"
 ... />
Taranfx
  • 10,361
  • 17
  • 77
  • 95