Game is getting closed in the background!?

I got this message from Google to solve:

Users will often switch between several tasks throughout the day, interrupting gameplay in some instances. For games that have a pause-state and aren’t reliant on real-world time progression or multiplayer gameplay, the game should be paused, when resumed from a minimized or locked state in order to keep users satisfied and engaged. Currently, the game reboots when the app is brought back into the foreground and all level progress is lost.

Can anybody help me with this and let me know how I can make sure a game in the background stays open and active and is not getting closed completely?

Add this line:

UIApplicationExitsOnSuspend = false,

This link will help you a lot:
https://code.tutsplus.com/tutorials/corona-sdk-handling-application-suspension–mobile-9777

Thanks for the info.

Isn’t this line UIApplicationExitsOnSuspend = false, depreciated code?

I am not sure if it is deprecated, but it is for iOS only.

I am not sure about the specifics, but Corona apps should remain in the background when the app is suspended (even though they aren’t running). Once the app is toggled again, everything should resume. There should, however, be a cut-off time after which the app will restart completely after being resumed. I’m not sure how long that is, i.e. if we are talking about tens of seconds or a few minutes, etc.

Thank you!

I need this for Google Play and it should be included, so the game can be considered for a feature.

How is this done by other games? Is this a Corona specific issue?

Well, apps that can run in the background are an entirely different thing. Corona apps don’t. For Corona apps and other apps that aren’t designed to run in the background, this should be the default behaviour.

So if we quote the reviewer, “Users will often switch between several tasks throughout the day, interrupting gameplay in some instances”, then the only way that you could accomplish that with Corona apps is by creating a save file on suspend event. When the user suspends the app, you could store information like in which level the player was, where their character was, etc. and when the game is resumed after a long pause, you’d check if the save file exists. If it does, then you’d take the player to where they were and delete the save file.

Depending on how your game is programmed, and what kind of game it is, this might mean you can return the player exactly to where they were, or you’d need to return them to the start of the level where they were, etc.

With the suspend state being “unsafe” because it is never sure if a file has enough time to get saved in this state the whole thing can not be done 100%.

Is there no other way to make sure a Corona build app can be “open” in the background for a longer period of time?

You can achieve the general stuff already when the level gets loaded, i.e. when the user loads level X, you create a savefile that contains all necessary information to bring the user back to said level with any possible settings.

Depending on the type of game you are dealing with, that could be enough. You could also consider having a different set of savefiles that you save after each move (again, this’d depend on the type of game you are working with, and it’d drain the battery if you save to disk too frequently).

Really, it all depends on the type of game you are developing. Most level based games don’t lend themselves to something like “instant resume”, whereas for some base building games this’d be super easy, barely an inconvenience.

Hi, I have problem with game reseting too.

In my case, the game resets instantly, meaning when I suspend it and resume it immediately after that, the game is restarted. You said there should be some time limit which in my case there isnt. This only happens when i activate 1 of three main buttons, so its not as bad. I use Huawei (dunno the version), android version 6. I wonder if someone else has the same problem.

Isnt that all controlled by the os? And as all Android manufacturers seem to have their own custom android it means that changes from phone to phone.

Okay, but how can other games manage to stay open then? What exactly is the difference to a Corona game?

OS automatically closes apps as it runs low of memory. Corona apps dont seem to have running background services and they are games so prolly bigger memory users than average apps so closing them frees much memory and with no services running closing em wont cause issues. But like really Ive never heard that apps must save state. Can anyone tell me one game that does?

Add this line:

UIApplicationExitsOnSuspend = false,

This link will help you a lot:
https://code.tutsplus.com/tutorials/corona-sdk-handling-application-suspension–mobile-9777

Thanks for the info.

Isn’t this line UIApplicationExitsOnSuspend = false, depreciated code?

I am not sure if it is deprecated, but it is for iOS only.

I am not sure about the specifics, but Corona apps should remain in the background when the app is suspended (even though they aren’t running). Once the app is toggled again, everything should resume. There should, however, be a cut-off time after which the app will restart completely after being resumed. I’m not sure how long that is, i.e. if we are talking about tens of seconds or a few minutes, etc.

Thank you!

I need this for Google Play and it should be included, so the game can be considered for a feature.

How is this done by other games? Is this a Corona specific issue?

Well, apps that can run in the background are an entirely different thing. Corona apps don’t. For Corona apps and other apps that aren’t designed to run in the background, this should be the default behaviour.

So if we quote the reviewer, “Users will often switch between several tasks throughout the day, interrupting gameplay in some instances”, then the only way that you could accomplish that with Corona apps is by creating a save file on suspend event. When the user suspends the app, you could store information like in which level the player was, where their character was, etc. and when the game is resumed after a long pause, you’d check if the save file exists. If it does, then you’d take the player to where they were and delete the save file.

Depending on how your game is programmed, and what kind of game it is, this might mean you can return the player exactly to where they were, or you’d need to return them to the start of the level where they were, etc.

With the suspend state being “unsafe” because it is never sure if a file has enough time to get saved in this state the whole thing can not be done 100%.

Is there no other way to make sure a Corona build app can be “open” in the background for a longer period of time?

You can achieve the general stuff already when the level gets loaded, i.e. when the user loads level X, you create a savefile that contains all necessary information to bring the user back to said level with any possible settings.

Depending on the type of game you are dealing with, that could be enough. You could also consider having a different set of savefiles that you save after each move (again, this’d depend on the type of game you are working with, and it’d drain the battery if you save to disk too frequently).

Really, it all depends on the type of game you are developing. Most level based games don’t lend themselves to something like “instant resume”, whereas for some base building games this’d be super easy, barely an inconvenience.

Hi, I have problem with game reseting too.

In my case, the game resets instantly, meaning when I suspend it and resume it immediately after that, the game is restarted. You said there should be some time limit which in my case there isnt. This only happens when i activate 1 of three main buttons, so its not as bad. I use Huawei (dunno the version), android version 6. I wonder if someone else has the same problem.