-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Move android app initialization to custom application class #18756
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
Conversation
You can test this PR using the following package version. |
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.
Don't forget to add the breaking change to https://github.com/AvaloniaUI/Avalonia/wiki/v12-Breaking-Changes once the PR gets merged.
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.
LGTM!
You can test this PR using the following package version. |
I've added [<Application>]
type Application (javaRef, transfer) =
inherit AvaloniaAndroidApplication<FabApplication> (javaRef, transfer)
override _.CreateAppBuilder () =
Main.configureLogging ()
(Main.configure activated.Publish).UseAndroid ()
[<Activity(Label = "tst",
Theme = "@style/MyTheme.Starting",
LaunchMode = LaunchMode.SingleTop,
MainLauncher = true,
ConfigurationChanges = (ConfigChanges.Orientation ||| ConfigChanges.ScreenSize ||| ConfigChanges.UiMode))>]
type MainActivity () =
inherit AvaloniaMainActivity ()
override _.OnRequestPermissionsResult (c, p, r) =
Platform.OnRequestPermissionsResult (c, p, r)
base.OnRequestPermissionsResult (c, p, r)
override this.OnCreate s =
AndroidX.Core.SplashScreen.SplashScreen.InstallSplashScreen this |> ignore
base.OnCreate s
(this :> IAvaloniaActivity).Activated.Add activated.Trigger
Platform.Init (this, s) which as far as I can see mirrors changes to the samples in this PR. When I try to run this though, I get |
Please post the full stack trace and a simple reproduction |
Never mind, I think #18806 is the actual problem, because I tracked the error to a EDIT: yeah, the build from #18832, which includes commits from this PR, fixes the problem. Nevertheless, it's bizarre that this started manifesting after moving to 12.0.999-cibuild0056440-alpha from the previous build 12.0.999-cibuild0056436-alpha. |
What does the pull request do?
Adds an Application class to the android backend and moving initialization to it. This ensures that no matter which activity is launched, the avalonia subsystem will be initialized with the correct App class.
What is the current behavior?
App initialization on android only occurs when the main activity is launched. Any other activity launched before or without the main activity will use the default avalonia Application, thus styles and resources will not get loaded. I'm guessing this behaviour was added just to get the android backend up and running, and hasn't been fixed since.
What is the updated/expected behavior with this PR?
Avalonia App is initialized once in a process, and any activity launched hosting an avalonia control will have access to app styles.
How was the solution implemented (if it's not obvious)?
Checklist
Breaking changes
All android projects targeting nightly or v12 will have to be updated.
AvaloniaMainActivity<TApp>
is removed in favor of adding an Application class that derives from theAvaloniaAndroidApplication<TApp>
class.Obsoletions / Deprecations
Fixed issues