Advertisement Jump to content
Sign in to follow this  
tom_mai78101

When using GLSurfaceView, it is possible onSurfaceCreated() can be executed more than once per session.

This topic is 1761 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		//Checks if the object is loaded already or not.
		//EXAMPLE:
		if (this.entity == null)
			this.entity = new Entity();
	}
The above code shows an Entity object being loaded when the Surface has been created. I've recently found out that there are times when the onSurfaceCreated() method is executed more than once while the app is running, without any orientation changes or screen goes dirty.

By using if... conditional checks, it will help prevent accidental reloading.

I'm just sharing what I know. Side question: Should this be written as a dev journal?

Share this post


Link to post
Share on other sites
Advertisement

The OS will destroy your app more times than not when the screen orientation changes.  It will also do it for stuff like when a keyboard is slid out.  If you put the following in the AndroidManifest.xml, it will prevent most of these cases.

 

<activity android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" </activity>

 

The OS can also destroy your surface if something covers your app but there are ways around this.  I believe NVidia has one of the best papers on this subject but I forget where.  Good place to look is in thier Android SDK in one of thier white papers. 

Share this post


Link to post
Share on other sites
I believe NVidia has one of the best papers on this subject but I forget where. Good place to look is in thier Android SDK in one of thier white papers. 

 

Could be Android lifecycle for application developper, they really make a good job explaining lifecycle events hierarchy:

 

https://developer.nvidia.com/sites/default/files/akamai/mobile/docs/android_lifecycle_app_note.pdf

 

Another article that really helped me when I coded my game loop on android is this one:

 

http://www.altdevblogaday.com/2013/08/18/the-main-loop-in-devils-attorney-on-android/

 

it have a part about lifecycle events and compatibility issues, always interesting to see how other developers manage to handle edge cases.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!