Re: How to end SDLActivity correctly

Triang3l <[email protected]> Wed, 14 Dec 2016 23:49:47 +0300
Newsgroups gmane.comp.lib.sdl
Message-ID <[email protected]>
You can use exit() the same way as you use it on other OSes, and it will 
kill all activities and services currently running in the calling 
process (by default, there is one process for all activities and 
services, but using the android:process attribute in AndroidManifest.xml 
you can put different components of your application into different 
processes - but you won't need it most of the time).

If you're making a game with the traditional singleton lifecycle, it's 
perfectly fine to use exit() and other per-process things such as global 
variables, while using the singleTask launch mode to maintain only one 
activity for your game (the activity basically being the drawing surface 
and input interface). It's simply not possible to respect the Android 
lifecycle with everything being local to activity and saved/restored 
during configuration changes (mostly you can even skip configuration 
changes at all using the android:configChanges attribute, and/or only 
handle special cases such as font size changes) when you have a game any 
more complex than Pong or whatever anyway.

It's just not how you should design regular apps. Games rarely need the 
activity-based interaction model, so the singleton architecture is both 
acceptable and a common practice.

SDL is designed in the way that allows having multiple activities and 
services of the same application running simultaneously, so it doesn't 
kill the process by itself, but rather notifies the application code 
that an exit was performed. So it's the application's responsibility to 
handle the quit event as it needs it to be handled - and if you need to 
kill the whole process, nothing can stop you from killing the whole process.

On 14/12/2016 20:28, hardcoredaniel wrote:
> You cannot completely "exit" an Activity on Android (like on Windows 
> or other OSes where exit() resp. return from main unloads the program 
> from memory). Android will decide for itself whether and when to 
> remove an Activity from memory. Think of it like files that an OS will 
> cache in memory for performance reasons - Android does the same with 
> Activities.
>
> An Activity being in the "destroyed" state should however not behave 
> differently when started, compared to an Activity that has not been 
> started before. And yes, Android apps should always be restartable, 
> because you'll never know whether the app was removed from memory in 
> the meantime. This might need special attention (like no static 
> initialization in native code, and SDLActivity re-initializing some 
> fields upon onDestroy() already, which looks strange but is correct).
>
>
> ---------- Původní zpráva ----------
> Od: Edition Chamäleon <[email protected]>
> Komu: [email protected]
> Datum: 14. 12. 2016 17:15:31
> Předmět: Re: [SDL] How to end SDLActivity correctly
>
>
>     Hi Daniel,
>
>     thank you for your fast answer. Resuming my app, when it is paused
>     via homebutton works fine. But the exitbutton that I want to
>     implement should kill the app complete and shut it down.
>     As I wrote I'm killing all of my native app, when the exitbutton
>     is triggered by the user, therefore it isn't restartable anymore.
>     Is that a wrong way?
>     Michael
>     _______________________________________________
>     SDL mailing list
>     [email protected]
>     http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>
>
> _______________________________________________
> SDL mailing list
> [email protected]
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list
[email protected]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org