From 3a482ebae062cbc127e4e0faf9a07f69b54b7419 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 4 Nov 2023 21:18:16 -0700 Subject: [PATCH] Add createSDLMainRunnable() to SDLActivity (thanks Cole!) This patch adds a new createSDLMainRunnable() method to SDLActivity. Currently, SDL on Android expects to find SDL_main somewhere in native code. When using SDL in a Xamarin application, however, what we really want to do is write our entrypoint in managed code. The easiest way to do this is to allow subclasses of SDLActivity to provide their own Runnable to the SDL thread, as in the attached patch. Fixes https://github.com/libsdl-org/SDL/issues/2785 --- .../app/src/main/java/org/libsdl/app/SDLActivity.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 a80b4941fb..41497a71e6 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 @@ -238,6 +238,15 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh return mMotionListener; } + /** + * This method creates a Runnable which invokes SDL_main. The default implementation + * uses the getMainSharedObject() and getMainFunction() methods to invoke native + * code from the specified shared library. + */ + protected Runnable createSDLMainRunnable() { + return new SDLMain(); + } + /** * This method returns the name of the shared object with the application entry point * It can be overridden by derived classes. @@ -783,7 +792,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh // Start up the C app thread and enable sensor input for the first time // FIXME: Why aren't we enabling sensor input at start? - mSDLThread = new Thread(new SDLMain(), "SDLThread"); + mSDLThread = new Thread(SDLActivity.mSingleton.createSDLMainRunnable(), "SDLThread"); mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true); mSDLThread.start();