5

我正在尝试使我的应用程序在 API<23 设备上完美运行,以在 API 23 设备上运行。它在以下场景中崩溃。用户通过 更改设置options menu。如果他们在菜单选项上缓慢点击(因此有时间看到该选项被突出显示),一切都很好,但如果他们短暂点击,应用程序就会崩溃。
我知道这是一种非常奇怪的行为,我花了一些时间试图了解是什么引发了错误。错误发生在 .recreate() 之后onOptionItemSelected。我在 recreate() 之前设置了一个超时来测试该选项是否“已验证”,但这不起作用。我只能想到 API 23 中的某种错误,因为它以前可以与其他 API 一起使用。这是我的代码片段(减少到最低限度):

@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)
4

1 回答 1

1

这确实是一个错误。在我报告之后,它已经被谷歌修复了。可以在这里关注:https ://code.google.com/p/android/issues/detail?id=195966

同时我的解决方法是替换recreate()为:

    Intent intent = getIntent();
    finish();
    startActivity(intent);

但是重新加载不像 recreate() 那样顺利(我可以看到一点闪烁)。

于 2016-05-19T09:36:41.713 回答