2015-10-20 43 views
5

我試圖使我的應用程序在API設備上完美工作,在API 23設備上工作。
基本上,當用戶通過選項菜單更改設置時,將使用recreate()重新創建活動。現在,如果我慢慢點擊菜單選項(所以我有時間看到選項被突出顯示),一切都很好,但如果我點擊一下,應用程序崩潰。
我知道這是一個退出奇怪的行爲,我很難理解是什麼引發了錯誤。我在重新創建()之前放了一段時間,所以也許這個選項是「驗證過的」,但是沒有奏效。 我只能想到API 23中的某種錯誤,因爲它之前與其他API一起工作。 這裏是我的代碼片段(沒什麼特別的):在API 23/Marshmallow中獲取onOptionsItemSelected()中recreate()的錯誤

@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); 
} 

和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) 

任何幫助或建議將是非常讚賞。

UPDATE:我絕對認爲API> 23中存在一個bug。創建一個空白活動的新項目,並在內部添加onOptionsItemSelected()

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

該應用程序仍然崩潰。

所以我解決方法是:

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

但重裝並不像重新創建平滑()(我可以看到一點點閃爍)。

+1

「我有錯誤信息」 - 請發佈Java堆棧跟蹤或其他錯誤消息。 – CommonsWare

+0

我仍然沒有看到日誌的問題,但recraete()可以替換invalidateOptionsMenu() – dex

+0

我已經嘗試invalidateOptionsMenu()但它沒有重新創建/刷新頁面的技巧。我用它來刷新菜單選項,它確實適用於此目的。 – Vega

回答