-
Notifications
You must be signed in to change notification settings - Fork 921
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
Document that multiple windows are not supported on Android #3505
base: master
Are you sure you want to change the base?
Conversation
One solution I can think of is letting |
I think we discussed that with @MarijnS95 at some point and I think there're issues with NDK stuff. In general window should allow create |
This would probably be quite challenging to support currently while our model for making it feel like you're running a regular, native Rust app with a "main" function on Android revolves around dedicated activity subclasses that help us track the lifecycle for the app. Some work was done to avoid the use of static global state in In an app I work on we do end up creating additional activities at time to open a web view but this is currently as an un-integrated special case via some Java code where there's no requirement for additional activities to also be driven by native Rust code + Winit. I'd guess this direction could be more practical if we had our own RustActivity and maybe a separate RustSubActivity or something for managing something akin to multiple windows. I'm not sure this would currently be practical based on |
I think I've been led to believe it was impossible to have two activities in a single process, but that doesn't sound like it is the case, at least not if you use some Java code? Can they be both be on-screen at the same time, e.g. in split screen mode, or one of them on a separate display? Do they have to run on separate threads? Do you register them as separate activities in the application manifest?
Maybe you can expand on how sub-activities work, or just link to some documentation about that parent/child relationship? |
far from impossible, it's quite common for a regular Android application to involve more than one Activity which may be started via Intents and they would typically run in the same process. multiple activities associated with an application would be declared in the AndroidManifest.xml and an Intent could be used to launch those activities. but more specifically in the context of a typical 'native' application on Android; those are typically implemented via some special Activity sub classes (i.e so it's not a fundamental limit of Android that you can't have multiple activities that can stack on top of each, or e.g. be arranged side-by-side on larger screen but the Hypothetically we could implement our own RustActivity subclass of Activity that could somehow be tailored to allow a single native Rust program to follow the lifecycle of multiple activities within a single process. Some details of that could be quite awkward if trying to think of an Activity like a Window. For instance the Probably in this context (looking for what multiple Windows in Winit could map to - or for something similar to subviews for #3506 ) then I think it's probably This is also where the built-in Again hypothetically though, with a RustActivity we could potentially try and break down that assumption and make it easier to create multiple SurfaceViews which could then each be cast as a NativeWindow for Rust code. Even without a special RustActivity it might be possible that we could create a SurfaceView via JNI potentially and then use There are probably some thorny details that would be involved, but in principle I think perhaps that Winit could do all that via JNI and have good amount of flexibility with adding multiple windows/surface views to the activities root ViewGroup.
Hopefully the above notes give a bit more detail. My naming was probably misleading where I mentioned a 'RustSubActivity' because there's no such special thing as a 'sub activity', but with the way that activities are declared via the manifest for an android application I was vaguely imagining that for a native Rust application wanting to track multiple activities then it might make sense to have a dedicated Activity class for ancillary activities that wouldn't each run a separate |
/// not be closed by dropping the [`Window`]. | ||
/// - **Web:** The window is represented by a `HTMLElementCanvas`, and cannot | ||
/// currently be closed by dropping the [`Window`]. | ||
/// - **Android:** Each window is spawned inside its own process, and as such |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy-pasting my reply in #696 (comment):
on Android each window is run in its own process
Not at all, anything related to the same app (services, multiple
Activities
which are probably the closest synonym toWindows
) should all run in the same process.This is actually an open issue, where certain Android system interactions can cause it (the Android system) to launch another
Activity
one is already open via a callback. Bothandroid-activity
andwinit
are assuming there is only oneActivity
singleton with (related) state stored across variousstatic
globals, and everything falls apart.It is however unlikely to have multiple windows open at the same time, bar tricks with multiple task stacks, split-window, popout windows and perhaps desktop mode.
I wouldn't mention process boundaries at all. Rather:
- Spawning windows in Android most likely doesn't perform in the way the user expects. This could navigate to a different "page" in an app but it's not at all like the desktop experience;
- The Android system can spawn new "windows" (Activities) for you (e.g. an app resize or display mode change, or via public
Intent
s launched by other apps) on its own behalf.
This thought appears to be correct from a Rust+winit+ndk-glue/android-activity perspective, as none of the crates are set up to deal with this, even though it is super common in Android as already elaborated by @rib. I don't see a compelling use-case in supporting opening multiple None of this is however a good reason to not implement support for multiple |
Not sure exactly what to write here, but I wanted the docs to talk about it somewhere.
Unless my understanding is wrong of course, and it is possible for Winit to support multiple windows / activities at some point?
CC @rib @MarijnS95