xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.64k stars 1.88k forks source link

Unpreventable Acitivity re-creation on physical keyboard connection change #15720

Closed EORG-Dev closed 6 months ago

EORG-Dev commented 1 year ago

Hi everyone,

whenever I plug in a physical keyboard (USB/Samsung-POGO/Bluetooth) my applications activity is re-created. This behaviour is expected and there is a known fix for it: Adding ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden to the MainActivity as per the following SO Post: https://stackoverflow.com/questions/18444476/android-crashes-on-keyboard-plugging

Expected behaviour: The Activity is not recreated an there is no interuption of the users interaction with the app. Actual behaviour: The Activity is recreated

To recreate this issue: I recommend to create a blank project. Launch the MainPage as NavigationPage and add a Button to it. Then create a new empty page and navigate to it. This makes the recreation very visible as after the re-creation the navigation root is shown. This also represents the situation in my app very closely.

So far I did a lot of research on this, although I have no native android development experience. There also seems to be a surprising amount of other, commercial Apps that also crash on this configchange.

Thanks in advance, feel free to ask for more info

EORG-Dev commented 6 months ago

I found a workaround for this issue in this thread: https://github.com/xamarin/xamarin-android/issues/2963

It also points out that this issue might be on the android system side of things.

Short answer: Also add ConfigChanges.Navigation to the main activity