在 Android 上,应用程序在方向更改时跳回默认页面

Ste*_*eAp 3 xamarin xamarin.forms

我在 iOS 和 Android 上测试了我的Xamarin.Forms应用程序,当我改变移动设备的方向时发现了这种差异:

  • 在 iOS 上,应用保持当前页面
  • 在 Android 上,应用程序似乎使用默认页面重新启动(或者可能弹出除第一个页面之外的所有页面)。

由于我从未在其他 Android 应用程序中看到过这种行为,因此我想禁用它。此外,我不认为这种行为是 Android 的默认行为。

我需要设置哪个属性才能使 Android 目标表现得像 iOS 目标?

ad1*_*ima 5

您是否检查了 MainActivity 的ActivityAttribute?它应该指定ConfigChanges.Orientation

像这样的东西

using Android.Content.PM;

[Activity(Label = "%Your app name%", MainLauncher = true, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
Run Code Online (Sandbox Code Playgroud)

如果 ConfigChanges.Orientation 未设置,操作系统将在方向更改时重新创建 Activity。如果设置了,则表示您将自己管理方向更改。