开发者

Activity has leaked window on orientation change with a SubMenu opened

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>
开发者_Python百科

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.


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"
 ... />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜