Background mode

Hi Guys,

Just put a test of my first major Corona app on my Ipad - looks great! Couple of questions.

  1. When I hit the home button, do something else and then go back to my app, it starts from the beginning. How do I put it into some sort of background sleep mode.

  2. How do I end an app progammatically - is there an exit command? (“end” in Visual Basic)

Thanks

Adrian [import]uid: 83824 topic_id: 18756 reply_id: 318756[/import]

Have a look at this thread covering the onSystemEvent API.

http://developer.anscamobile.com/forum/2011/10/29/how-pause-game#comment-64371

onSystemEvent is called when the app is paused, interrupted, resumed, or exited. It provides the hooks you need to save state and resume based on certain system activity.

-David
[import]uid: 96411 topic_id: 18756 reply_id: 72168[/import]

Let me ask you a question about ending your game…

How many of your other iOS apps have a quit button? I almost every case, the expected behavior is on signout, game over, etc. is to return to a main menu where the user can begin anew.

So if you have your game quit, it won’t be like any other app on the device. [import]uid: 19626 topic_id: 18756 reply_id: 72193[/import]

I put this line in my build.settings file:

UIApplicationExitsOnSuspend = false,

and now I’m getting the behavior you say you want. I can hit the home button and leave my app. When I restart my app, it is running in the same screen as when I left it. It does not go back to the main menu. Since I don’t have an exit button in my app, the only way to really kill it, is the double tap of the home button method that lets you kill background apps in iOS.

I haven’t submitted this update yet, because I’m not sure if this is really what users want. I kind of agree with what @robmiricle says about exiting and restarting an app. But I have found some other apps that work this way. For example, Angry Birds. If I leave it and restart it later it acts like the game was just paused. [import]uid: 67839 topic_id: 18756 reply_id: 72292[/import]

Thanks to all of you for your replies. I am new to the IPad/Iphone programming world. In my Windows programs, I am just so used to ending my programs neatly and clearing out memory etc… It just feels so odd to have my app just sort of lying there but I get your point robmiracle. Thanks elbowroomapps, I will look into the ExitsOnSuspend = False - it seems to be exactly what I want.

Does all this mean that my app, once run will always be in the background until the user turns their device off? Seems a new, scary sort of culture to me!!! Thanks david97, all that seems kind of complex for what I want to do but I will revisit it if the ExitsOnSuspend = False doesn’t work for me.

Thanks again

Adrian [import]uid: 83824 topic_id: 18756 reply_id: 72383[/import]

Just tried the ExitsOnSuspend = False and have run into a problem. My app is Landscape only - my Build .settings file includes:

orientation =
{
default = “landscapeRight”,
supported =
{
“landscapeRight”, “landscapeLeft”
},
},

When I add the ExitsOnSuspend line, my app turns to portrait. Have seen a few others on the forum getting this problem as well!

Any ideas?

Adrian [import]uid: 83824 topic_id: 18756 reply_id: 72402[/import]

See what happen using this: [lua]content = “landscapeRight”[/lua]

here:

[lua]orientation =
{
default = “landscapeRight”,
content = “landscapeRight”, supported =
{
“landscapeRight”, “landscapeLeft”
},
},[/lua]

But please take into account that it`s just a miserable sugestion trying to help you not a “sure” answer. :slight_smile:
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 18756 reply_id: 72404[/import]

Thanks Rodrigo, unfortunately it didn’t work. Not actually sure where in build.settings I am supposed to put the UIApplicationExitsOnSuspend = false line but no where seems to work even with your new line in - everything still portrait.

Thanks for trying

Adrian [import]uid: 83824 topic_id: 18756 reply_id: 72408[/import]

You`re welcome Adrian.

So, I`ll give you my own build.settings config file just changed to work with your own necessary settings (eg.: “landscapeRight”…).

Check it below:

[lua]-- Supported values for orientation:
– portrait, portraitUpsideDown, landscapeLeft, landscapeRight

settings =
{
orientation =
{
default =“landscapeRight”,
content = “landscapeRight”,
supported =
{
“landscapeLeft”
},
},

iphone =
{
plist =
{
–UIStatusBarStyle = “UIStatusBarStyleBlackTranslucent”,
UIStatusBarHidden = true,
UIPrerenderedIcon = true, – set to false for “shine” overlay
UIApplicationExitsOnSuspend = false,

CFBundleIconFile = “Icon.png”,
CFBundleIconFiles = {
“Icon.png”,
“Icon@2x.png”,
“Icon-72.png”,
},
},
},

}

–[[ For Android:

androidPermissions = {
“android.permission.INTERNET”,
},
]]–[/lua]

PS: In this code above you can see where we need to set that line about “suspend” as well. :slight_smile:

Hope it helps!
Rodrigo. [import]uid: 89165 topic_id: 18756 reply_id: 72409[/import]

A couple of things to keep in mind with this whole resume on suspend/backgrounding apps.

If you want your app to exit, then don’t turn on the background mode. That way each time your user restarts the app, it will restart anew.

Backgrounding is only available on iOS 4.0 and later. Devices running earlier OS’s will still exit on suspend. [import]uid: 19626 topic_id: 18756 reply_id: 72415[/import]

I don’t think exiting on suspend is a good idea Adrian. If an iPhone user gets a phone call then they can lose their progress. [import]uid: 31262 topic_id: 18756 reply_id: 72425[/import]

UIApplicationExitsOnSuspend = false

:slight_smile: [import]uid: 89165 topic_id: 18756 reply_id: 72426[/import]

Thanks agaian guys.

robmiracle, I wouldlike my app to “pause” when the user hits the home button and resume when the app’s icon is reclicked. When you say “turn on background mode” do you mean inserting the “UIApplicationExitsOnSuspend = false” in the build.settings file?

I haven’t tried Rodrigo’s build.settings file yet (thanks Rodrigo) but up to now I’ve not been able to get the “suspend” working while still keeping my Landscape aspect. My app only works in Landscape and the “UIApplicationExitsOnSuspend = false” line forces the app into Portrait mode.

Hi aaaron, I think you’ve got me the wrong way round. Instead of “exiting on suspend” I want to “suspend on exiting”. Noticed your logo of 30 below - are you in Alaska or somewhere cold or have I missed the point?

Thanks again all

Adrian [import]uid: 83824 topic_id: 18756 reply_id: 72477[/import]

Hi Adrian,

Using Rodrigo’s suggestions should work. My game runs landscape and suspends when you press the home button and resumes when you start it back up and I have a similar setup to that one.

I am located in Canada. It’s not always cold here, the company name is more of a play on the stereotypes. Good luck! [import]uid: 31262 topic_id: 18756 reply_id: 72480[/import]

FANTASTIC! It works! Thanks Rodrigo and robmiracle. Just for your info Rodrigo, I took out the Content line and everything still ok.

Thanks again

Adrian [import]uid: 83824 topic_id: 18756 reply_id: 72497[/import]

If your game supports vertical mode, but starts in landscape, then most likely when a person resumes the game from an iPhone, they are in vertical mode and the app would switch to that.

Here is my build.settings file:

settings =  
{  
 iphone =  
 {  
 plist=  
 {  
 UIInterfaceOrientation = "UIInterfaceOrientationLandscapeLeft",  
 UISupportedInterfaceOrientations =  
 {  
 "UIInterfaceOrientationLandscapeLeft",  
 "UIInterfaceOrientationLandscapeRight"  
 },  
 MinimumOSVersion="3.2.0",  
 UIApplicationExitsOnSuspend = false,  
 UIPrerenderedIcon="YES",  
 UIStatusBarHidden=true,  
 CFBundleIconFile = "Icon.png",  
 CFBundleIconFiles = {  
 "Icon.png" ,   
 "Icon@2x.png" ,   
 "Icon-72.png" ,   
 "Icon-Small-50.png" ,   
 "Icon-Small.png" ,   
 "Icon-Small@2x.png"  
 },  
 UIAppFonts =  
 {  
 "actionj.ttf",  
 "SAF.otf",  
 },  
 },  
 },  
 orientation =  
 {  
 default = "landscapeLeft",  
 supported =  
 {  
 "landscapeRight", "landscapeLeft"  
 },  
 },  
}  
  

This stays in horizontal orientation, and resumes when I click back on the game.
[import]uid: 19626 topic_id: 18756 reply_id: 72504[/import]

Glad to help @adrian.

PS: Believe, this community is awesome. Welcome! :slight_smile:
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 18756 reply_id: 72572[/import]

Hey @rob ,

Thanks posting this full build.settings file. :slight_smile:

I did not have one like this as yet. hehe

Cheers,
Rodrigo. [import]uid: 89165 topic_id: 18756 reply_id: 72574[/import]