I have this weird issue only on android where if I push the home button, when I get back into the game it passes through resume() and it display by background texture correctly. But if I push the back button it destroy and when I get back it the game it calls create(), but it draws the background as a white texture instead.

I searched a bit on the subject and what I know so far:

  • Android static variables are not reinitialized on activity recreation, so you must make sure that create() will initialize those variables.
  • OpenGL will free the textures when the application loses focus, so this is why they must be reloaded when the application resume.

Unfortunately, even having this information in mind while programming did not fix the issue. I'll just show important portion of the code below:

// The asset manager is created statically, but not initialized
private static AssetManager _manager;

//Then during the create() and resume() method, the manager is initialized and all the 
//textures will be loaded afterwards.
_manager = new AssetManager();

//When the app is destroyed, dispose() is called and the manager is nullified
_manager = null;

So given the code above, if the application is destroyed or resumed, they will both pass into the same initialization method that creates the assets manager and load textures.

So why it only works on resume() and not on create() when the same code is actually called.

A quick fix that worked was something I found on this forum which consisted in killing the application on disposal with the following code in the android project:

//SOURCE: https://gamedev.stackexchange.com/questions/102079/screen-not-rendering-after-restarting-game
protected void onDestroy() {
    android.os.Process.killProcess(android.os.Process.myPid()); // this line will kill process

But I am not sure it is the right way to do things.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.