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
main
Sam Lantinga 2023-11-04 21:18:16 -07:00
parent b9784feb24
commit 3a482ebae0
1 changed files with 10 additions and 1 deletions

View File

@ -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();