Libgdx解決部分Android機(jī)型鎖屏崩潰的方法
libgdx使用了全屏模式之后,在某些機(jī)型會(huì)出現(xiàn)崩潰的情況,兩年前就存在了,一直到現(xiàn)在為止,官方都沒進(jì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!"); } } } }
崩潰的提示就是在這個(gè)方法中進(jìn)行拋出的,解決方法就是,不讓他拋出這個(gè)錯(cuò)誤,就是在try里面把pause改為false,目前的解決方法是這樣子,靜候官方的修復(fù)了,自定義一個(gè)類,例如我用的是AndroidFragmentApplication,我自定義一個(gè)PatchedAndroidFragmentApplication,在onPause之后利用線程延遲100毫秒,執(zhí)行一個(gè)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就繼承這個(gè)自定義的類就行。
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
- 詳解 Android中Libgdx使用ShapeRenderer自定義Actor解決無法接收到Touch事件的問題
- 詳解Android Libgdx中ScrollPane和Actor事件沖突問題的解決辦法
- Android使用libgdx實(shí)現(xiàn)模擬方向鍵控制角色移動(dòng)的方法
- Android 游戲引擎libgdx 資源加載進(jìn)度百分比顯示案例分析
- Android drawable微技巧,你不知道的drawable細(xì)節(jié)
- Android指紋識(shí)別API講解,一種更快更好的用戶體驗(yàn)
- Android在Kotlin中更好地使用LitePal
- Android Studio輕松構(gòu)建自定義模板的步驟記錄
- 詳解Android 檢測(cè)權(quán)限的三種寫法
- Android最簡(jiǎn)單的狀態(tài)切換布局實(shí)現(xiàn)教程
- android自定義環(huán)形對(duì)比圖效果
相關(guān)文章
Android基于OpenCV實(shí)現(xiàn)非真實(shí)渲染
非真實(shí)感渲染(Non Photorealistic Rendering,簡(jiǎn)稱NPR),是指利用計(jì)算機(jī)模擬各種視覺藝術(shù)的繪制風(fēng)格,也用于發(fā)展新的繪制風(fēng)格。比如模擬中國(guó)畫、水彩、素描、油畫、版畫等藝術(shù)風(fēng)格。本文將講解Android基于OpenCV實(shí)現(xiàn)非真實(shí)渲染的方法2021-06-06Android提高之多級(jí)樹形菜單的實(shí)現(xiàn)方法
這篇文章主要介紹了Android多級(jí)樹形菜單的實(shí)現(xiàn)方法,很實(shí)用的功能,需要的朋友可以參考下2014-08-08Android Studio中導(dǎo)入JNI生成的.so庫(kù)的實(shí)現(xiàn)方法
這篇文章主要介紹了Android Studio中導(dǎo)入JNI生成的.so庫(kù)的實(shí)現(xiàn)方法的相關(guān)資料,這里不僅提供實(shí)現(xiàn)方案并提供了實(shí)現(xiàn)的方法,需要的朋友可以參考下2017-07-07Android開發(fā)之自定義view實(shí)現(xiàn)通訊錄列表A~Z字母提示效果【附demo源碼下載】
這篇文章主要介紹了Android開發(fā)之自定義view實(shí)現(xiàn)通訊錄列表A~Z字母提示效果,結(jié)合完整實(shí)例形式分析了Android獲取通訊錄列表及采用自定義view排列顯示的相關(guān)操作技巧,需要的朋友可以參考下2017-07-07Android 多圖上傳后將圖片進(jìn)行九宮格展示的實(shí)例代碼
這篇文章主要介紹了Android 多圖上傳后將圖片進(jìn)行九宮格展示,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-11-11深入android Unable to resolve target ''android-XX''詳解
本篇文章是對(duì)android Unable to resolve target 'android-XX'錯(cuò)誤的解決方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06