Fixed bug 3933 - Android, no need of the listener thread Sylvain A listener thread has been added to know when the native thread would end. But now, it is more easy to only check that after the main function has returned. It's one thread less.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
index ae0bc81..75e18bb 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
@@ -371,27 +371,8 @@ public class SDLActivity extends Activity {
// Start up the C app thread and enable sensor input for the first time
// FIXME: Why aren't we enabling sensor input at start?
- final Thread sdlThread = new Thread(new SDLMain(), "SDLThread");
+ mSDLThread = new Thread(new SDLMain(), "SDLThread");
mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
- sdlThread.start();
-
- // Set up a listener thread to catch when the native thread ends
- mSDLThread = new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- sdlThread.join();
- } catch (Exception e) {
- // Ignore any exception
- } finally {
- // Native thread has finished
- if (!mExitCalledFromJava) {
- handleNativeExit();
- }
- }
- }
- }, "SDLThreadListener");
-
mSDLThread.start();
}
@@ -1044,6 +1025,11 @@ class SDLMain implements Runnable {
SDLActivity.nativeRunMain(library, function, arguments);
Log.v("SDL", "Finished main function");
+
+ // Native thread has finished, let's finish the Activity
+ if (!SDLActivity.mExitCalledFromJava) {
+ SDLActivity.handleNativeExit();
+ }
}
}