Issue #35 wontfix
Martin Felis repo owner created an issue

Currently we issue a call to exit() at the end of love.cpp which works but is a hack. Apparently it is possible to end the application nicer.

Comments (10)

  1. Landon “Karai” Manning

    Exiting an app in Android is considered bad practice. Instead of calling exit(), you should call finish(). Finish exits the current activity and, if no other Activities are in the stack, takes you to the home screen. Android will then exit the app if need be via garbage collection. Otherwise, when you click to open the app again, it should open normally and not be the same "exited" instance.

  2. Martin Felis reporter

    The exit() I was referring to has to be called on the native side. It basically causes the App to crash, which in turn removes the App from the "Recent Apps" list that you can see if you press the "Recent Apps Button" (i.e. the button on the very right since Android 4.0 http://www.android.com/about/ice-cream-sandwich/).

    Removing this native exit() call, runs the java onFinish() method but leaves the app in the "Recent Apps" list but crashes when clicking on it. In the upcoming SDL 2.0.2 this crash is fixed and instead the app starts as if it was newly started.

    It feels weird to leave it there, but I guess this the default Android behaviour. So consider it almost fixed.

  3. Martin Felis reporter

    We still quit the App using exit(retval); in jni/src/love.cpp. Removing it causes problems as LÖVE has some static variables defined where it tracks the instances of certain modules, e.g. Filesystem and Thread.

    If we do not call exit(retval);and the app gets restarted it reuses the same memory. The mentioned static variables then still contain the addresses to the instances of the previous run. The problem is that the instances are created in jni/love/src/common/runtime.cpp and their memory is not reused and therefore the static instances point to invalid locations and cause segfaults.

    It would probably more work to change LÖVE in this regard so we'll just keep it as is.

  4. Reenen Laurie

    Is there a way I can rerun the "load" function when I open the app up again? Like park it in a different function than "load" perhaps "activate" or something similar?

  5. Alex Szpakowski

    You can call love.load() in love.focus or any other place if you want, although it might not do what you expect if you have files which you require inside love.load and/or local variables inside the files.

  6. Reenen Laurie

    Yeah I think love.focus is gonna do it for me thanks! I will still need more testing, but it looks promising.

  7. Alex Szpakowski

    Removing it causes problems as LÖVE has some static variables defined where it tracks the instances of certain modules, e.g. Filesystem and Thread.

    As of the latest mobile-common, those particular static variables are gone. It's now 'possible' to do a pseudo-restart without calling exit(), however there might be issues with games that use threads which aren't cleaned up properly when the game quits (you should signal the thread to finish its Lua code and then call thread:wait() to properly clean up a thread), and it's possible there are other static variables LÖVE uses that could cause issues (although if so I'd consider that a bug and I'd try to fix it.)

    I don't know what's considered good practice on Android, but on iOS programatically exiting the app in any way (including but not limited to exit()) can get the app rejected from the App Store - there are no games I know of in the iOS App Store which have a 'quit' button.

  8. Pablo Mayobre

    In Android, games with the quit button remain as zombie app. And if you enter a zombie app it will just restart.

  9. Log in to comment