[ios/android] game restarts when home button is pressed

[ios/android] When you press home button, and then you go back. Does it restarts? instead of going back to where it was.
I tried putting Director::sharedDirector()->pause(); on AppDelegate::applicationDidEnterBackground() so that the game will pause when player presses home button, and if the player goes back to the game it should go back to where it was. But in my case, the game restarts, it goes back from the start. Specifically goes back on the splash screen.

1 Like

I’m currently investigating the exact same thing. My game isn’t doing anything special when going to/returning from the background state, yet the game restarts and state is lost. Have you found your issue yet ?

Nope, I haven’t figured out yet. I tried telling a friend of mine about this, he said that his game is fine it doesn’t restart if player presses the home button, but his cocos2d-x version was 2+. Im using version 3.3. What cocos2d-x version you use?

Out of the box cocos2d-x has always had normal resuming for me. I’m currently on 3.2. The normal behavior for ios is that the app should resume when restarted. Any closed waiting app is eligible by system to be closed if memory is needed.

You should test with a basic Hello World. Install on actual device and see of you can get that to resume.

It makes sense that the game should resume when restarted, but, I’m not doing anything to actually restart the app. My question stills stands, what could be causing a game that is in the background to restart when it is brought back to the foreground.

PS: I’m only testing on actual devices (iOS and Android).

I figured it out. It doesn’t work on some devices. I tried it on other phones, it resumes as intended.

Which devices? I’m seeing this happen on 5, 5s, Galaxy S3 / S4. For the most part, it resumes properly on those devices, except from time to time when you go back to the app it restarts. I’d say 80% of the time the app resumes properly, but once in a while it resets.

Im not sure if you are familiar with Cherry Mobile.

Hey, I’m fairly convinced that the issues we were experiencing in regards to restarts were related to TTF fonts. I know that TTF renderings would get corrupted and end up into blocks on Android, so there’s definitely something wrong with that part of the API. I’ve replaced all TTF fonts with BMFonts and I’m not seeing the restart issue/android crashing anymore.

Hope this helps.

1 Like

Thank you Nick… will check on this