【发布时间】:2016-01-19 14:18:37
【问题描述】:
我正在尝试使我的应用程序在 APIoptions menu 更改设置。如果他们慢慢点击菜单选项(因此有时间看到该选项被突出显示),一切都很好,但如果他们短暂点击,应用程序就会崩溃。
我知道这是一种非常奇怪的行为,我花了一些时间试图了解是什么引发了错误。错误发生在onOptionItemSelected 中的 recreate() 之后。我在 recreate() 之前设置了一个超时来测试该选项是否“已验证”,但这不起作用。
我只能想到 API 23 中的某种错误,因为它以前可以与其他 API 一起使用。
这是我的代码的 sn-p(减少到最低限度):
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_1:
//... some code goes here
recreate();
return true;
// some other options ..
}
return super.onOptionsItemSelected(item);
}
创建一个带有空白活动的新项目并在 onOptionsItemSelected() 中添加后
if (id == R.id.action_settings) {
recreate();
return true;
}
应用仍然崩溃。
这里是日志:
10-20 23:12:10.062 3217-3245/? E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab3d1b80 10-20 23:12:11.050 3217-3245/? E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb4013030 10-20 23:12:11.075 3217-3245/? E/Surface: queueBuffer: error queuing buffer to SurfaceTexture, -19 10-20 23:12:11.075 3217-3245/? E/EGL_emulation: tid 3245: swapBuffers(324): error 0x3003 (EGL_BAD_ALLOC) 10-20 23:12:11.075 3217-3245/? A/OpenGLRenderer: Encountered EGL error 12291 EGL_BAD_ALLOC during rendering 10-20 23:12:11.075 3217-3245/? A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 3245 (RenderThread)
【问题讨论】:
-
“我有一条错误消息”——请发布 Java 堆栈跟踪或其他错误消息。
-
通过查看日志我仍然没有什么问题,但是 recraete() 可以替换为 invalidateOptionsMenu()
-
我已经尝试过 invalidateOptionsMenu() ,但它无法重新创建/刷新页面。我用它来刷新菜单选项,它确实适用于此目的。
-
这里是来自另一个相关帖子的potential solutions SO。这可能会有所帮助。
标签: android android-activity android-6.0-marshmallow recreate