Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Context Menu - Exception due to MenuBuilder$MenuAdapter changing without AlertController$RecycleListView receiving a notification
    primarykey
    data
    text
    <p>I've searched high and low to find an answer to why our application is crashing when a user will click on one Context Menu item and then repeatedly clicks on another. Here is the stack trace I have, which is all on Android internal classes:</p> <pre><code>11-11 15:08:30.904: ERROR/AndroidRuntime(3489): FATAL EXCEPTION: main 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(16908808, class com.android.internal.app.AlertController$RecycleListView) with Adapter(class com.android.internal.view.menu.MenuBuilder$MenuAdapter)] 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at android.widget.ListView.layoutChildren(ListView.java:1550) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at android.widget.AbsListView.onTouchEvent(AbsListView.java:2192) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at android.widget.ListView.onTouchEvent(ListView.java:3377) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at android.view.View.dispatchTouchEvent(View.java:3766) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1720) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1117) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at android.app.Dialog.dispatchTouchEvent(Dialog.java:642) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1704) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at android.view.ViewRoot.handleMessage(ViewRoot.java:1794) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at android.os.Handler.dispatchMessage(Handler.java:99) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at android.os.Looper.loop(Looper.java:143) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at android.app.ActivityThread.main(ActivityThread.java:4701) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at java.lang.reflect.Method.invokeNative(Native Method) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at java.lang.reflect.Method.invoke(Method.java:521) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 11-11 15:08:30.904: ERROR/AndroidRuntime(3489): at dalvik.system.NativeStart.main(Native Method) 11-11 15:08:30.912: WARN/ActivityManager(1261): Force finishing activity com.pyxismobile.pyxWholesaler.ui.activity/.GNBActivity 11-11 15:08:30.943: WARN/WindowManager(1261): No window to dispatch pointer action 1 11-11 15:08:30.943: WARN/WindowManager(1261): No window to dispatch pointer action 0 11-11 15:08:30.943: WARN/WindowManager(1261): No window to dispatch pointer action 1 </code></pre> <p>The basic design we have is on an Activity class we override the onCreateContextMenu and onContextMenuItem. On the create, the code basically populate a collection of MyMenuItems where each item has a run method to execute whatever we need the menu item to do. The onContextMenuItem basically takes the ID from the MenuItem passed in, looks up on the collection the given id, and then just runs that run method.</p> <p>To try and narrow down what the cause is, I've commented out the run portion to do nothing. This still causes the exception. I didn't see anything special going between the creation and clicking where we would modify any data. Everything is done once in the creation.</p> <p>I tried to create a very simple test app, however I could not get this exception to occur. I've also briefly looked at the internal Android source code to see if I could figure out anything, but nothing came to light.</p> <p>If anyone has any suggestions on what I may be doing wrong, or what to look into it would be appreciated.</p> <p>Edit: I've also determined for this to be device agnostic. I have been able to recreate on multiple devices, however on rare occasion it does not happen. My assumption is there is some sort of race condition.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload