API 23/棉花糖中onOptionsItemSelected()内部的recreate()错误 [英] Getting an error on recreate() inside onOptionsItemSelected() in API 23 / Marshmallow

查看:132
本文介绍了API 23/棉花糖中onOptionsItemSelected()内部的recreate()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使我的应用程序在API< 23设备上完美运行,以便在API 23设备上运行. 它在以下senario中崩溃. 用户通过options menu更改设置.如果他们在菜单选项上缓慢点击(以便有时间看到突出显示的选项),则一切都很好,但是如果短暂点击,则应用程序将崩溃.
我知道这是一种奇怪的行为,并且我花了一些时间试图了解引发该错误的原因.错误出现在onOptionItemSelected中的recreate()之后.我在recreate()之前放置了一个超时,以测试该选项是否为"validated",但这不起作用. 我只能想到API 23中的某种错误,因为它以前曾与其他API一起工作过. 这是我的代码段(缩减到最少):

I am trying to make my App, which works perfectly on API<23 devices, to work on an API 23 device. It crash in the following senario. The user changes settings via options menu. If they tap slowly on the menu option (so there is time to see the option being highlighted), everything is fine, but if they tap briefly, the App crashes.
I know it's a quit strange behaviour and I have spend some time trying to understand what fires the error. The error occurs after recreate() which is in onOptionItemSelected. I put a timeout before recreate() to test if the option is "validated" but that didn't work. I can only think of some kind of bug in API 23 because it worked before with other APIs. Here is a snippet of my code (cut down to a minimum):

@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()内部添加

After creating a new project with a blank activity and just adding inside onOptionsItemSelected()

if (id == R.id.action_settings) {
    recreate();
    return true;
}

该应用仍然崩溃.

这是logcat:

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)

推荐答案

这确实是一个错误.在我报告之后,此问题已由Google修复. 可以在此处进行以下操作: https://code.google.com/p/android/issues/detail?id = 195966

This was indeed a bug. After I reported, it has been since fixed by Google. It can be followed here: https://code.google.com/p/android/issues/detail?id=195966

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

Meantime my workaround is to replace recreate() by:

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

但是重新加载的效果不如recreate()平滑(我可以看到有点闪烁).

But the reload is not as smooth as with recreate() (I can see a little flashing).

这篇关于API 23/棉花糖中onOptionsItemSelected()内部的recreate()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆