Hi,
I’m using Activity.finish() to do that. I defined myself a Handler in
SDLActivity.java
??? protected Handler exitHandler = new Handler() {
??? ??? public void handleMessage(Message msg) {
??? ??? ??? finish();
??? ??? }
??? };
and I send a message to that Handler when the SDL C thread terminates.
??? // Runs SDL_main()
??? SDLActivity.nativeInit();
??? // Log.v(“SDL”, “SDL thread terminated”);
???
??? exitHandler.sendEmptyMessage(0);
???
The call to finish() triggers the lifecycle management of the Android system
to “tear down” the app (although the virtual machine will not necessarily
exit). In the process of that, “onDestroy()” is called and that will nicely
terminate everything.
My solution is not really elegant, as it requires you to hand the reference
to the “exitHandler” all the way to the SDLMain class. But it works
Regards,
Daniel
---------- P?vodn? zpr?va ----------
Od: Jared Maddox
Datum: 24. 11. 2013
P?edm?t: Re: [SDL] SDL2 Android - Exiting
"> Date: Sat, 23 Nov 2013 00:16:38 -0400> From: Alvin Beach
To: SDL Development List
Subject: Re: [SDL] SDL2 Android - Exiting
Message-ID: <52902C26.8010509 at gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
My
statement about “SDL_Quit() and the state of the app” was concerning
the state of the threads. When main() returns, it’s thread presumably
dies. This leaves the Java thread running. I believe there is no scenario
to get main() to start up again. The app needs to be terminated and
restarted for main() to run again.
Technically, this depends on the code that called main() in the first
place, but I agree with you that it’s doubtful that such a
"reincarnation" technique is incorporated there. Even if it is,
presumably anything that fixes the orphaned-thread problem can later
be extended to work in that case too.
From what I can see in the source is that the Java-side of the SDL2
project
properly terminates itself when told to by the OS (i.e. onDestroy() I
believe).
I am wondering if there is a way to trigger that behaviour from within the
C++ code.
Maybe there’s a way to ask the OS to do the termination? All that’s
really needed is (at least I hope) to slip the call to main() between
the initial setup, and the final tear-down of the C++ thread, while
signalling at the end of that thread that the Java thread should exit
too.
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org"