Skip to content

Separate android initialization from Activity #11891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 10, 2025

Conversation

isXander
Copy link
Contributor

@isXander isXander commented Jan 8, 2025

Separates initialization and JNI hooks from SDLActivity, into a separate class SDLActivityComponent. SDLActivity uses this to apply the functionality onto the activity.

Description

Currently, all SDL initialization on Android is done within an Activity. Whilst this is good for simplicity, it doesn't allow a lot of flexibility for Android apps; some apps' activities may already inherit something else, making it extremely impractical to get SDL to work.
Removing all functionality from the activity into a separate class, SDLActivityComponent, allows developers to compose the SDL glue code into their existing activity. SDLActivity remains, as a simple semi-backwards-compatible way that also demonstrates how to use the new SDLActivityComponent.

Existing Issue(s)

#11890

@VenomousSteam81
Copy link

Very cool!

@isXander
Copy link
Contributor Author

isXander commented Jan 8, 2025

Whilst on the topic of the java library, Android Studio picked up a few errors:

  • HIDDeviceBLESteamController.java requires permission android.permission.BLUETOOTH_CONNECT
  • HIDDeviceManager.java: mUsbBroadcast is missing RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED flag for unprotected broadcasts registered for org.libsdl.app.USB_PERMISSION

@isXander
Copy link
Contributor Author

isXander commented Jan 8, 2025

All relevant test environments are passing now. Failures match base branch.

@isXander
Copy link
Contributor Author

isXander commented Jan 8, 2025

Ready for review!

@slouken slouken merged commit d14c93c into libsdl-org:main Jan 10, 2025
22 of 40 checks passed
@slouken
Copy link
Collaborator

slouken commented Jan 10, 2025

Merged, thanks!

slouken added a commit that referenced this pull request Jan 10, 2025
This reverts commit d14c93c.

This is a major breaking change for activities that inherit SDLActivity
@slouken
Copy link
Collaborator

slouken commented Jan 10, 2025

This ended up being a major breaking change for activities that inherit from SDLActivity, so we don't want this to go in so close to 3.2.0 release.

Here's a sample of the kinds of things that broke:

error: component has private access in SDLActivity
                component.setWindowStyle( true );

error: method does not override or implement a method from a supertype
error: COMMAND_CHANGE_WINDOW_STYLE has protected access in SDLActivityComponent
    @Override
    protected boolean sendCommand(int command, Object data)
    {       
        if ( command == SDLActivityComponent.COMMAND_CHANGE_WINDOW_STYLE && (Integer)data == 0 )

error: mLayout has protected access in SDLActivityComponent
                SDLActivityComponent.mLayout.addView( m_videoSurface );

@isXander
Copy link
Contributor Author

Would you accept a second PR that addresses the backwards compatibility more? Providing more overridable methods in SDLActivity to configure the component?

@slouken
Copy link
Collaborator

slouken commented Jan 12, 2025

Would you accept a second PR that addresses the backwards compatibility more? Providing more overridable methods in SDLActivity to configure the component?

Sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants