Fixed bug 3933 - Android, no need of the listener thread
authorSam Lantinga <slouken@libsdl.org>
Thu, 02 Nov 2017 08:46:14 -0700
changeset 11670cb780bb5093a
parent 11669 1fe21a20aa12
child 11671 3dc400fafd76
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.
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Wed Nov 01 19:19:21 2017 -0700
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Thu Nov 02 08:46:14 2017 -0700
     1.3 @@ -371,27 +371,8 @@
     1.4                      // Start up the C app thread and enable sensor input for the first time
     1.5                      // FIXME: Why aren't we enabling sensor input at start?
     1.6  
     1.7 -                    final Thread sdlThread = new Thread(new SDLMain(), "SDLThread");
     1.8 +                    mSDLThread = new Thread(new SDLMain(), "SDLThread");
     1.9                      mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
    1.10 -                    sdlThread.start();
    1.11 -
    1.12 -                    // Set up a listener thread to catch when the native thread ends
    1.13 -                    mSDLThread = new Thread(new Runnable() {
    1.14 -                        @Override
    1.15 -                        public void run() {
    1.16 -                            try {
    1.17 -                                sdlThread.join();
    1.18 -                            } catch (Exception e) {
    1.19 -                                // Ignore any exception
    1.20 -                            } finally {
    1.21 -                                // Native thread has finished
    1.22 -                                if (!mExitCalledFromJava) {
    1.23 -                                    handleNativeExit();
    1.24 -                                }
    1.25 -                            }
    1.26 -                        }
    1.27 -                    }, "SDLThreadListener");
    1.28 -
    1.29                      mSDLThread.start();
    1.30                  }
    1.31  
    1.32 @@ -1044,6 +1025,11 @@
    1.33          SDLActivity.nativeRunMain(library, function, arguments);
    1.34  
    1.35          Log.v("SDL", "Finished main function");
    1.36 +
    1.37 +        // Native thread has finished, let's finish the Activity
    1.38 +        if (!SDLActivity.mExitCalledFromJava) {
    1.39 +            SDLActivity.handleNativeExit();
    1.40 +        }
    1.41      }
    1.42  }
    1.43