[REQUEST] Support multiple windows on Android

Hello!

Android has Multi-Window support since API 24. Currently SDL requires API >= 26, so all Android versions supported by SDL have this feature.

Android’s Multi-Window support is not limited to displaying multiple apps on one screen, you can also launch multiple activities of the same app (for example, Chrome can do that):
Launch New Activities in Multi-Window Mode - from developer.android.com

Also Android devices can support “freeform windows”, i.e. basically a desktop-like experience.

Currently the code in SDL_androidwindow.c won’t allow opening more than one window:

SDL_SetError(“Android only supports one window”);

I think multiple windows should be supported on Android. Are there any technical challenges that currently prevent this?

Thanks

1 Like

My understanding is that it only requires API >= 16 to run. See ‘Requirements’ here.

Thank you for the correction.
So that means this feature will also require a check if Multi-Window is supported (API Level < 24) and a fallback to the current behavior if it isn’t.

Hello,

Currently SDL can run in multi-window, you can resize the window, share the screen with another app, get/lose focus, etc. Indeed it doesn’t allow to create more than one window.

Once, I tried to patch SDL to create several pseudo windows by simply creating several surfaceView, so that windows were in fact “layers”, z-ordered. This worked, but this wasn’t representative of SDL functionnalities.

It should be possible to create several genuine windows with several activities.
Currently SDLActivity creates surfaceview, and when all is ready, starts the C main.
With several windows, it’s going to be a little bit messier, with some re-factoring needed.
A compromise for simplication could be to have a master window (the root activity), and several other.

That would be great, especially knowing that genuine windows can take advantage of Android’s features designed for windows, such as system-wide drag&drop (which is another feature in scope of SDL and worth considering).

What would happen if the user closed the master window in that case?

What parts of SDL do you think would be involved in such refactoring? Is it a lot of work?

I tried to patch SDL2 for allowing the creation of multiple SDL_Window on Android.
Each one in a new activity, with no root activity limitation.
This is an unfinished patch. most secondary features are not tested, and it has bugs for sure.
But you can find the patch here: https://bugzilla.libsdl.org/show_bug.cgi?id=5173

1 Like

Thank you! It’s amazing how fast this went from a discussion to a working prototype. Looks interesting!
I won’t be able to test it for the next couple of weeks, unfortunately, but definitely will do later.

Also, I want to comment on this bit:

I wonder whether starting a SDL_Window in a new instance of activity is a good choice, maybe it should be run in what android call “fragment” ?

AFAIK, there is no other option besides using 1 activity per SDL_Window.
Consider the freeform mode on Android:


In the freeform mode, apps are displayed in native floating windows, and some apps can use multiple windows, like Gmail in this screenshot:
image

This isn’t possible with just 1 activity.

If you wish to test it but your device doesn’t support the freeform mode, there’s a way to enable it using ADB:

adb shell settings put global enable_freeform_support 1

A reboot may be required for this to take effect.
Also I think some devices (especially phones) may not enable the freeform mode regardless of the setting.