Skip to content
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

Android: Setup Appbuilder being called multiple times #8330

Closed
marcussacana opened this issue Jun 11, 2022 · 5 comments · Fixed by #9154
Closed

Android: Setup Appbuilder being called multiple times #8330

marcussacana opened this issue Jun 11, 2022 · 5 comments · Fixed by #9154

Comments

@marcussacana
Copy link

The bug
When the app isn't entire closed, if we try open the app again, the Avalonia Activity OnCreate method is triggered again and causes the problem.

To Reproduce

  1. Start your application
  2. "Exit" pressing "Back" (That should keep the app running in background)
  3. Try return to your app without close it
  4. Throws this error:
System.InvalidOperationException: Setup was already called on one of AppBuilder instances
   at Avalonia.Controls.AppBuilderBase`1[[Avalonia.AppBuilder, Avalonia.PlatformSupport, Version=0.10.999.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b]].Setup() in /_/src/Avalonia.Controls/AppBuilderBase.cs:line 302
   at Avalonia.Controls.AppBuilderBase`1[[Avalonia.AppBuilder, Avalonia.PlatformSupport, Version=0.10.999.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b]].SetupWithLifetime(IApplicationLifetime lifetime) in /_/src/Avalonia.Controls/AppBuilderBase.cs:line 179
   at Avalonia.Android.AvaloniaActivity`1[[Sample.App, Sample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnCreate(Bundle savedInstanceState) in /_/src/Android/Avalonia.Android/AvaloniaActivity.cs:line 52
   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState)
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0)
  • OS: Android 10
  • Version 0.10.15 + 0.10.999-cibuild0019213-beta
@marcussacana
Copy link
Author

marcussacana commented Jun 11, 2022

I forgot, but my stock phone ROM is infamous for causing bugs because of the aggressive battery optimization.
I don't have another phone to test it, then maybe my issue may be invalid.

@kekekeks
Copy link
Member

@maxkatz6 I think we should

  1. move AppBuilder initialization from AvaloniaActivity to a separate AvaloniaMainActivity class
  2. have some static fields in said class to initialize only once and keep Content alive between instances

@maxkatz6
Copy link
Member

have some static fields in said class to initialize only once and keep Content alive between instances

AndroidX with android-viewmodel sharing was added for that matter before. See #7435

But I think we can move it to the separated activity and remove androidx from dependencies list.

@maxkatz6
Copy link
Member

@marcussacana I can reproduce it as well, so most likely not related to your phone

@marcussacana
Copy link
Author

thx guys!

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

Successfully merging a pull request may close this issue.

3 participants