applicationExit event not triggered on Device

I’m at point of finishing my game, this means it is almost done, and have many features tested successfully in the past, but i jusr realized, that a previously working event handler doesn’t do it’s job anymore. The case is simple, the applicationExit system event is not triggered anymore on the device. In simulator it works perfectly. In my case some game related variables are saved at this time, and database is also closed in this handler.

This issue is present (at least) from build version #976, and still there with the latest build #1008.
Tested on iPhone4, iPhone4S, iPad2, iPad3 iOS 5 & iOS 6

Did anyone also experienced this issue?
It can be tested with a simple print command.

in main.lua:

[code]
local function onSystemEvent( event )
if event.type == “applicationExit” then
print(“applicationExit system event triggered only in simulator”)
–if BI.game then game.onExit() end
–db.updatesettings()
–db.closedb()
end
end

Runtime:addEventListener( “system”, onSystemEvent )
[/code] [import]uid: 88330 topic_id: 35213 reply_id: 335213[/import]

Typical iOS apps do not exit. They suspend. You will only get the exit event under two circumstances. 1. The user double presses the home button, taps and holds your app until it starts shaking, then they tap the minus badge. This force kills the app and you should get an applicationExit event.

  1. You turn off the ability for your app to go into the background when suspended by adding this line to your build.settings plist section:
UIApplicationExitsOnSuspend = true,  

However, doing so isn’t normal app behavior for iOS and Apple may not like it. You probably want to use the applicationSuspend event as another way to save your data. [import]uid: 199310 topic_id: 35213 reply_id: 140004[/import]

You misunderstood me!

I know the difference between suspend and exit, and my App also does different things in each case.
I just need to handle the event in your (1) example.
The problem is then that applicationExit event is not triggered (ublike earlier) when iOS quit application (power off or application closed from dock).

So please reflect to this issue in regard of the aboves.

PS: closing databases in this event like in my example in the topic is one of the examples taken from your site. Also the API documentation mention that when thns event have to be triggered, and it does right in the simulator, but not anymore on any of my devices. [import]uid: 88330 topic_id: 35213 reply_id: 140008[/import]

This isn’t something that has changed, it’s just the way iOS works (actually, pretty much every platform). When you manually force-close an application it is terminated with extreme prejudice and the app doesn’t get any chance to do anything (Corona is unaware that it has happened).

I’ve asked that the documentation is updated to reflect this.

As mentioned, applicationSuspend is probably the best place to handle things as, if you are suspended, there’s no guarantee you’ll ever be resumed. [import]uid: 199237 topic_id: 35213 reply_id: 140144[/import]

Thanks Perry!

Now it’s clear. My goal is to make a last game stat saving, when a device drains its battery, or a user switch it off. I can manage it to do it a different way, [import]uid: 88330 topic_id: 35213 reply_id: 140161[/import]

Typical iOS apps do not exit. They suspend. You will only get the exit event under two circumstances. 1. The user double presses the home button, taps and holds your app until it starts shaking, then they tap the minus badge. This force kills the app and you should get an applicationExit event.

  1. You turn off the ability for your app to go into the background when suspended by adding this line to your build.settings plist section:
UIApplicationExitsOnSuspend = true,  

However, doing so isn’t normal app behavior for iOS and Apple may not like it. You probably want to use the applicationSuspend event as another way to save your data. [import]uid: 199310 topic_id: 35213 reply_id: 140004[/import]

You misunderstood me!

I know the difference between suspend and exit, and my App also does different things in each case.
I just need to handle the event in your (1) example.
The problem is then that applicationExit event is not triggered (ublike earlier) when iOS quit application (power off or application closed from dock).

So please reflect to this issue in regard of the aboves.

PS: closing databases in this event like in my example in the topic is one of the examples taken from your site. Also the API documentation mention that when thns event have to be triggered, and it does right in the simulator, but not anymore on any of my devices. [import]uid: 88330 topic_id: 35213 reply_id: 140008[/import]

This isn’t something that has changed, it’s just the way iOS works (actually, pretty much every platform). When you manually force-close an application it is terminated with extreme prejudice and the app doesn’t get any chance to do anything (Corona is unaware that it has happened).

I’ve asked that the documentation is updated to reflect this.

As mentioned, applicationSuspend is probably the best place to handle things as, if you are suspended, there’s no guarantee you’ll ever be resumed. [import]uid: 199237 topic_id: 35213 reply_id: 140144[/import]

Thanks Perry!

Now it’s clear. My goal is to make a last game stat saving, when a device drains its battery, or a user switch it off. I can manage it to do it a different way, [import]uid: 88330 topic_id: 35213 reply_id: 140161[/import]