最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Libgdx解決部分Android機型鎖屏崩潰的方法

 更新時間:2018年10月18日 11:21:42   作者:tpnet  
今天小編就為大家分享一篇關(guān)于Libgdx解決部分Android機型鎖屏崩潰的方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧

libgdx使用了全屏模式之后,在某些機型會出現(xiàn)崩潰的情況,兩年前就存在了,一直到現(xiàn)在為止,官方都沒進行修復(fù),其崩潰原因就是在源碼AndroidGraphics.java中的onPause可以看到這樣子的一段代碼:

void pause () {
    synchronized (synch) {
      if (!running) return;
      running = false;
      pause = true;
      while (pause) {
        try {
          // TODO: fix deadlock race condition with quick resume/pause.
          // Temporary workaround:
          // Android ANR time is 5 seconds, so wait up to 4 seconds before assuming
          // deadlock and killing process. This can easily be triggered by opening the
          // Recent Apps list and then double-tapping the Recent Apps button with
          // ~500ms between taps.
          synch.wait(4000);
          if (pause) {
            // pause will never go false if onDrawFrame is never called by the GLThread
            // when entering this method, we MUST enforce continuous rendering
            Gdx.app.error(LOG_TAG, "waiting for pause synchronization took too long; assuming deadlock and killing");
            android.os.Process.killProcess(android.os.Process.myPid());
          }
        } catch (InterruptedException ignored) {
          Gdx.app.log(LOG_TAG, "waiting for pause synchronization failed!");
        }
      }
    }
  }

崩潰的提示就是在這個方法中進行拋出的,解決方法就是,不讓他拋出這個錯誤,就是在try里面把pause改為false,目前的解決方法是這樣子,靜候官方的修復(fù)了,自定義一個類,例如我用的是AndroidFragmentApplication,我自定義一個PatchedAndroidFragmentApplication,在onPause之后利用線程延遲100毫秒,執(zhí)行一個onDrawFrame,使得pause為false即可:

open class PatchedAndroidFragmentApplication : AndroidFragmentApplication() {
  private val exec = Executors.newSingleThreadExecutor()
  private val forcePause = Runnable {
    try {
      Thread.sleep(100)
    } catch (e: InterruptedException) {
    }
    graphics.onDrawFrame(null)
  }
  override fun onPause() {
    if (activity!!.window.attributes.flags and WindowManager.LayoutParams.FLAG_FULLSCREEN == WindowManager.LayoutParams.FLAG_FULLSCREEN) {
      // 是全屏
      exec.submit(forcePause)
    }
    super.onPause()
  }
}

然后你的Fragment就繼承這個自定義的類就行。

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接

相關(guān)文章

最新評論

湘阴县| 调兵山市| 汽车| 固镇县| 龙游县| 东丽区| 邹城市| 深州市| 团风县| 工布江达县| 湘西| 游戏| 和平区| 台南市| 定州市| 五寨县| 金坛市| 枞阳县| 新余市| 锦州市| 乌拉特后旗| 常熟市| 年辖:市辖区| 和顺县| 象山县| 井冈山市| 大名县| 连南| 含山县| 亳州市| 涟源市| 苗栗市| 德令哈市| 贵定县| 黔西县| 澳门| 宝应县| 庆元县| 胶南市| 会昌县| 大安市|