How are we suppose to exit an application?
Should we use os.exit() or native.requestExit() - neither one seems to work for me.
Thanks
Larry
How are we suppose to exit an application?
Should we use os.exit() or native.requestExit() - neither one seems to work for me.
Thanks
Larry
You should use native.requestExit(). If it’s not exiting, perhaps that part of your code is not being reached. Without seeing your code it’s going to be hard to help.
Rob
ok, I’ll check out my code in more detail and give it a try.
Thanks
Larry
I also tried exiting my app using either of the methods mentioned above (in my back button listener) but none of them worked for me neither. So I just return false in the part of back button’s listener logic where I want the app to exit - this works for me.
Belay my answer… I didn’t notice that this was the WP8 forum. The native.requestExit() thing is the right way for Android. I don’t know the proper protocol for Windows 8 users, though I don’t know why os.exit() shouldn’t work. Let’s wait on Joshua to answer this.
My apologies.
I retested using the the normal corona simulator and saw that my code had an error in it. I fixed the error and yes os.exit() works just fine.
so to recap
os.exit() - works !!!
native.requestExit() – does not work
thanks
Larry
The best solution is to return false for the back key event and let the OS back out of the app naturally.
The native.requestExit() is the next best solution and is set up to navigate back from your WP8 page, which would exit out of the app. This used to work back when we demoed Corona during the GDC and Microsoft Build conferences, but admittedly, I haven’t tested it in a while. I’ll re-test it next week to see what’s going on. (I have a sneaking suspicion that it only fails to exit the app when the CoronaPanel is set up to render to a DrawingSurfaceBackgroundGrid XAML control in the MainPage… and would work if you disable background rendering, but that will kill your framerate.)
I don’t recommend that you use os.exit() on any platform, because that forcefully terminates the app immediately in a not so nice way. You won’t get an “applicationExit” event if you do this.
I am expecting to have an Exit button in my app, not just force the user to keep pressing the back button until they get out of the app.
so if the requestExit was working that would be just fine with me. The requestExit did not work in the simulator, but I can test it on the device for verification.
Larry
I’m not sure if Microsoft allows GUI exit buttons at all. According to their design guides devs should rely on hardware buttons for back and exit functions. If you want to exit the app instantly you just press the middle home (start) button.
Jetpak Joyride has Exit button. and a prompt when it is clicked… Are you sure you want to exit.
So I don’t this it should be a problem. Also forcing a user to keep touching the back button is just a bad design. they should have an easy way to exit.
Larry
There’s a back button but there’s also a start (middle) button. The one with windows logo. When you hit it - you exit app instantly. Like a home button on iOS.
yep I know, my cell is a win 8.1 phone.
These buttons should work exactly like android
Back button should go back screen by screen - just like android.
The home button should suspend just like android - the OS cleans up suspend apps as needed.
Side note on Win 8 phone
If you hold the Back Button down for several seconds all running apps will display in which you can switch between them and your app will / should suspend, or you can kill the app by clicking on the presented (x) in the righ hand corner.
Larry
Microsoft has design guidelines for how to handle backing out or exiting the app here…
http://msdn.microsoft.com/en-us/library/windows/apps/dn148258(v=vs.105).aspx
While they would typically prefer that you back out of an app naturally, there is a blurb in their guidelines that it’s okay to just back out to the root page if the end-user is several pages deep within an app. Games and other media style apps typically get a pass on how to handle navigation, such as showing an “Are you sure?” before backing out of the app in case you accidentally tap the back button. I think the bottom line is that the navigation of your app just has to make sense. Although, I think they generally prefer that you take advantage of the Back button for navigation instead of an onscreen button.
Everyone,
I’ve looked into this issue. The native.requestExit() function will actually work if your app has pages to navigate back to, but it won’t do anything if your app has no more pages in its history. That is, it won’t exit the app. After refreshing my brain as to why, it’s because WP8’s native APIs does provide a nice means of exiting an app like Android. The only native WP8 API available to exit the app is to forcefully quit the app, much like how os.exit() works now.
But that said, I’ve implemented a bit of a hack-ish solution that is the closest equivalent to exiting the app like Android. Calling native.requestExit() will be non-blocking like Android, all of your app’s XAML controls will be “Unloaded”, you’ll receive an “applicationExit” event in Lua, and then the app will be forcefully terminated. Unfortunately, you’ll never receive a “Closing” event in your “App.xaml.cs” because it’s been forcefully exited (if you’re even using it). This forceful quit will be a bit noticeable because your app won’t do the slide-out animation when exiting out, which is what you normally see when pressing the back key. Instead, it simply blacks-out and the previous screen appears. Because of this, I highly recommend that you let your app be gracefully closed via the Back key event by *not* returning true in your Lua key event listener if you can.
(Welcome to the challenges of cross-platform development.)
A new build of CoronaCards for WP8 should be made available to you all later today.
Thanks for bringing up this issue.
You should use native.requestExit(). If it’s not exiting, perhaps that part of your code is not being reached. Without seeing your code it’s going to be hard to help.
Rob
ok, I’ll check out my code in more detail and give it a try.
Thanks
Larry
I also tried exiting my app using either of the methods mentioned above (in my back button listener) but none of them worked for me neither. So I just return false in the part of back button’s listener logic where I want the app to exit - this works for me.
Belay my answer… I didn’t notice that this was the WP8 forum. The native.requestExit() thing is the right way for Android. I don’t know the proper protocol for Windows 8 users, though I don’t know why os.exit() shouldn’t work. Let’s wait on Joshua to answer this.
My apologies.
I retested using the the normal corona simulator and saw that my code had an error in it. I fixed the error and yes os.exit() works just fine.
so to recap
os.exit() - works !!!
native.requestExit() – does not work
thanks
Larry
The best solution is to return false for the back key event and let the OS back out of the app naturally.
The native.requestExit() is the next best solution and is set up to navigate back from your WP8 page, which would exit out of the app. This used to work back when we demoed Corona during the GDC and Microsoft Build conferences, but admittedly, I haven’t tested it in a while. I’ll re-test it next week to see what’s going on. (I have a sneaking suspicion that it only fails to exit the app when the CoronaPanel is set up to render to a DrawingSurfaceBackgroundGrid XAML control in the MainPage… and would work if you disable background rendering, but that will kill your framerate.)
I don’t recommend that you use os.exit() on any platform, because that forcefully terminates the app immediately in a not so nice way. You won’t get an “applicationExit” event if you do this.