国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

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

2019-10-21 21:37:37
字體:
來源:轉載
供稿:網友

libgdx使用了全屏模式之后,在某些機型會出現崩潰的情況,兩年前就存在了,一直到現在為止,官方都沒進行修復,其崩潰原因就是在源碼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,目前的解決方法是這樣子,靜候官方的修復了,自定義一個類,例如我用的是AndroidFragmentApplication,我自定義一個PatchedAndroidFragmentApplication,在onPause之后利用線程延遲100毫秒,執行一個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就繼承這個自定義的類就行。

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對VEVB武林網的支持。如果你想了解更多相關內容請查看下面相關鏈接


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江源县| 吉木乃县| 乌拉特后旗| 左贡县| 彰化县| 张家川| 安庆市| 启东市| 鄂托克旗| 三门峡市| 招远市| 通山县| 柳州市| 东阳市| 盈江县| 西安市| 忻州市| 绥中县| 洪洞县| 周口市| 米林县| 绥宁县| 简阳市| 兰西县| 清镇市| 黔西县| 青川县| 山东省| 昌平区| 柯坪县| 通山县| 全南县| 赞皇县| 沂水县| 武夷山市| 丽江市| 屏东县| 孟村| 哈巴河县| 丹江口市| 郓城县|