Xamarin android app restarting on orientation change with newer android versions

Felix Nogal 41 Reputation points
2023-01-24T14:02:58.48+00:00

Hi,

Our Xamarin android app is restarting whenever the device orientation is changed. We have configured the main activity with the following:

[Activity(Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

This seems to work with older Android versions such us Andorid 9 but with Android 12/13 devices the app restarts on orientation changes.

Any ideas why this is not working on newer Android versions?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
4,812 questions
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 41,496 Reputation points Microsoft Employee
    2023-01-25T08:49:25.89+00:00

    Hello,

    You can try to add ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize to your [Activity] attribute.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Oldest