【问题标题】:Getting an error on recreate() inside onOptionsItemSelected() in API 23 / Marshmallow在 API 23 / Marshmallow 中的 onOptionsItemSelected() 中获取 recreate() 错误
【发布时间】: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


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 2017-01-01
    • 2016-02-02
    • 2023-03-28
    • 2015-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多