Move android app initialization to custom application class#18756
Conversation
|
You can test this PR using the following package version. |
MrJul
left a comment
There was a problem hiding this comment.
Don't forget to add the breaking change to https://github.com/AvaloniaUI/Avalonia/wiki/v12-Breaking-Changes once the PR gets merged.
|
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. |
…UI#18756) * move android app initialization to custom application class * fix tests * update api suppression * address comments
…UI#18756) * move android app initialization to custom application class * fix tests * update api suppression * address comments
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