1

I created a NET MAU app from the official template and inside Platforms - Android - MainActivity.cs found this code:

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}

That means, .NET MAUI handles ConfigChanges.Orientation by itself. Why is that? Also I figured out that rotation still works, it's not blocked. But what does NET MAUI behind the scenes / what's the reason NET MAUI handles that manually?

stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270

1 Answers1

0

Also I figured out that rotation still works, it's not blocked.

If you want the screen to stay in Portrait or Landscape, you can set the ScreenOrientation as follows:

ScreenOrientation = ScreenOrientation.Portrait

Or

ScreenOrientation = ScreenOrientation.Landscape

Usage example:

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true,ScreenOrientation = ScreenOrientation.Portrait, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] 
public class MainActivity : MauiAppCompatActivity
{
}
Sigmarod
  • 85
  • 12
Jessie Zhang -MSFT
  • 9,830
  • 1
  • 7
  • 19