Hi,
I don’t know too much about SDL in detail, so I can’t say anything about
these events.
Under the hood, SDL for Android has a “Java” and a “Native” part.
The Java part handles the Android lifecycle. So in case your app is put into
background, the onPause() callback arrives. SDL should now tell the native
part to pause executing (and maybe save important data in case the app will
be killed). Upon onResume() SDL shall also resume the native thread.
In case the onDestroy() callback is called, SDL can tear down everything and
prepare for a (possible) new start of the app.
If the app was killed after onPause() - well, no need to worry about exiting
Whenever the app is paused, it should not consume CPU, i.e. everything
should just sit idle and wait to be woken up again by an event (like
onResume()).
The only special case to SDL is that your application “payload” (your game
or whatever) does no longer want to run, say from a user dialogue “Do you
really want to quit playing?”. In this situation, it makes no sense just to
pause the app (upon resuming you would still be in the state “post-I-wanted-
to-quit”), but you really want it to reach the same state where it is upon
onDestroy(), waiting to be started again or killed.
For that, the Java part of SDL will send a “finish()” request to the Android
system, as soon as the native thread is finished, i.e. SDL_main() returns.
So when the native thread exits normally, the app will enter the onDestroy()
state automatically.
Regards,
Daniel
---------- P?vodn? zpr?va ----------
Od: Martin Gerhardy <martin.gerhardy at gmail.com>
Datum: 6. 1. 2014
P?edm?t: Re: [SDL] SDL2 Android - Exiting
"Am 06.01.2014 10:05, schrieb hardcoredaniel:
Hi,
according to this
http://developer.android.com/reference/android/app/Activity.html#
ActivityLifecycle
an app shall just follow the lifecycle. Whether the VM is actually
shut down or not shall be left up to the system (typically only on low
memory). Just make sure that you clean up after onDestroy() such that
a call to onCreate() restores everything, just as if the VM was really
terminated in between.
Actually the VM of the app can be forcibly terminated on low memory
anytime after the onPause() call, so saving all relevant data should
be done at onPause() time. In onDestroy() you just tear down
everything so that another onCreate() will be successful in case the
VM was not terminated.
Anyway, that’s the theory (as far as I understand it). I’m not sure
that every device actually behaves like this
Regards,
Daniel
Thanks for the link and the feedback.
So the general rule would be to not exit the native app part manually,
but only rely on SDL_QUIT event, right?
Let SDL do the onDestroy stuff and handle SDL_APP_TERMINATING or
SDL_APP_WILLENTERBACKGROUND to shut everything down or save things.
So hitting the home or power button will let SDL pause the app
internally, no need to worry about and will resume it automatically,
too. Having the app “killed” then is up to Android itself. The only
things that annoys me is the bad feeling about letting the app run
forever until a system component that I don’t have any control on will
do it at some magic time. But I will still give it a try in the next
release.
Thanks all.
Regards
Martin_______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org"