我有一个使用Xamarin表单开发的应用程序,我的用户希望能够在Android的PIP模式下使用它。我已经尝试将其集成,但是当应用程序调整大小时,android的主要活动在应用程序刚刚运行时再次调用onCreate方法,因此应用程序被冻结并崩溃了。此外,该应用程序从头开始。
因此,我尝试搜索有关如何开发它的信息,但没有找到有关此信息。您能否给我一些技巧或示例,以了解如何在XIP上使用PIP模式正确运行Xamarin Forms的主要活动?
谢谢
我尝试了一个空白项目……什么都没有。当我看到onCreate方法被调用时……我试图只创建一次Core App()以便“继续”在哪里,但是它被冻结了。
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
var x = typeof(Xamarin.Forms.Themes.DarkThemeResources);
x = typeof(Xamarin.Forms.Themes.Android.UnderlineEffect);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
CachedImageRenderer.Init(true);
FFImageLoading.ImageService.Instance.Initialize(new Configuration());
ZXing.Net.Mobile.Forms.Android.Platform.Init();
ZXing.Mobile.MobileBarcodeScanner.Initialize(this.Application);
Xamarin.Forms.DependencyService.Register<ToastNotification>(); // Register your dependency
ToastNotification.Init(this);
LoadApplication(TVOnlineSpain.App.Instance);
……….
}
……….
}
我想让应用继续状态(在我的情况下,更频繁地在xamarin表单的页面上播放视频),而用户可以更改活动大小以更改全屏或使用本机PIP模式,而不是使其崩溃。您能给我一些有关如何避免此问题的建议吗?谢谢
最佳答案
如果要避免进入“画中画”模式时重新启动“活动”,则需要告诉操作系统该活动将处理布局配置更改。
根据Android文档,这些是您需要添加到“活动”中的更改。
ConfigChanges.ScreenSize
ConfigChanges.SmallestScreenSize
ConfigChanges.ScreenLayout
ConfigChanges.Orientation
像下面一样,在
Activity
上使用它们可以解决您的问题。namespace MyGreatNamespace.Droid
{
[Activity(Label = "MyGreatNamespace",
Icon = "@mipmap/icon",
Theme = "@style/MainTheme",
MainLauncher = true,
SupportsPictureInPicture = true,
ResizeableActivity =true,
ConfigurationChanges = ConfigChanges.ScreenSize |
ConfigChanges.SmallestScreenSize |
ConfigChanges.ScreenLayout |
ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
....
}
}
}
希望这可以帮助。-