In game Images disappear on Android device if i run from widget, but not when I install apk first time

时光总嘲笑我的痴心妄想 提交于 2019-12-07 15:17:03

问题


I created a game in with LibGDX, which works fine on my computer. I created a debug .apk in Android Studio via the Gradle View -> Build & then copied my android-debug.apk & android-debug-unaligned.apk to the download folder of my Android Device.

Now when on my android device I clicked on one of my files the device ask if I wanna install it and choose yes and subsequently I open my game and it run fine.

Now the porblem occurs when i quite the game and try to restart the game from the widget that after the installation has been put on my android-"desktop" (main screen with all the apps you can click).

If i start it from the widget my graphics are messed up and missing & i have no idea why? Logo image missing from splashscreen. When switching to MenuScreen the image there is missing. And when I switch to my game screen graphics get totally messed up.

When i re-install the game and run it again, there is no problem.

If anyone could help?


回答1:


The difference in your use cases is the state of the JVM that is running your application. In some cases the JVM is brand new, and everything works. However, if the JVM is recycled (because Android hasn't killed it, just put it in the background), you run into problems. The core of the problem is, most likely, that you have references to OpenGL state from the previous run when you re-start the application (e.g., OpenGL texture IDs from the first run are getting used on subsequent runs). Because OpenGL is a stateful driver, and an application's state is wiped when it loses context, you need to reload global OpenGL state.

See Android static object lifecycle for a description of the underlying problem and http://bitiotic.com/blog/2013/05/23/libgdx-and-android-application-lifecycle/ for some Libgdx-specific tips on diagnosing and dealing with it.



来源:https://stackoverflow.com/questions/26150098/in-game-images-disappear-on-android-device-if-i-run-from-widget-but-not-when-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!