Question

I'm making a game. Not long ago I had a problem. I wanted to preserve GLContext of GLSurfaceView for old sdk versions. I've solved this problem by getting newest source of GlSurfaceView and putting it in my project. Just little fix was needed: gles 2.0 version check.

That works almost good. But!

On android versions 2.x.x When screen tuns of the application is destroyed and context and all textures along with it. Interesting thing: if i'll press home button and application will go to background and the turn of screen it wont be destroyed, but if i'll turn of screen when it is running in foreground it will be destroyed for sure.

I've tried different approaches to avoid this.

  1. I've tried to separate context and surface threads as it was recommended by developers of replica island. But nothing good. It always reloads textures.

  2. I've tried to detach view n the onDestroy as was recommended here: Attach/detach Android view to/from layout but nothing good either.

  3. I've tried to use FLAG_SHOW_WHEN_LOCKED. But when screen is turned on the locker screen wont show up. And it will be shown when home button is pressed. Not good at all.

  4. I've tried to send app to background when on resume was called and then with BroadcastReceiver to bring it in foreground but it always is brought in foreground (even if it was in background). And if it was destroyed by system it wont be shown at all.

Don't know what to do. May be my phone runs low on resources, but i've tried other games and they work perfectly fine. And restore themself without long reloading.

Was it helpful?

Solution

I cant belive it. This is so stupid. According to this thread Problems understanding the life cycle when screen goes off and on you have to add

<activity ... android:configChanges="orientation" ... >

so the app wont be rotated and then destroyed when you will turn screen off.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top