Xamarin闪屏的例子并不在横向模式下的手机上运行。如何解决呢? [英] Xamarin Splash screen example does not work in landscape mode on a phone. How to fix it?

查看:343
本文介绍了Xamarin闪屏的例子并不在横向模式下的手机上运行。如何解决呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从网上下载Xamarin网站闪屏的例子:
http://developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/

I downloaded the splash screen example from the Xamarin website: http://developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/

我编译它,并运行它在我的手机:
http://www.gsmarena.com/samsung_galaxy_fresh_s7390-5841.php

I compiled it and ran it on my phone: http://www.gsmarena.com/samsung_galaxy_fresh_s7390-5841.php

据被人捧在肖像模式(垂直)我的电话时,工作正常。闪屏成为直接可见的,几秒钟后,随着按钮的观点变得可见。当关闭和重新启动应用程序,它仍然工作正常。

It was working fine when holding my phone in portrait mode (vertical). The splash screen became directly visible and after a few seconds, the view with the button became visible. When closing and restarting the application, it was still working fine.

在这之后,我又闭上了按住我的手机在横向(水平)模式。现在,我又开始了应用。我的手机被冻结了几秒钟,飞溅没有变得可见。在这之后,我看到我的按钮视图。

After that, I closed it again and hold my phone in landscape (horizontal) mode. Now, I started the application again. My phone was frozen for a few seconds, the splash did not become visible. After that, I saw my view with the button.

当您尝试重现此问题,请确保您:

When you try to reproduce this issue, make sure that you:


  • 请不要尝试重现它的虚拟设备(的行为是不同的)。

  • 确保该睡眠至少需要10秒,那么你真的看到了问题所在:冻结应用程序而不是一个闪屏

  • 如果您还没有三星的趋势精简版,您尝试在另外一个小的智能手机。我很难想象,这可能是一个三星趋势精简版只的问题。

我该如何解决这个问题?

How do I fix this?

推荐答案

借助 Xamarin样本你链接里面出现很大的问题:

The Xamarin sample that you linked has big problem within it:

[Activity(Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        Thread.Sleep(10000); // Simulate a long loading process on app startup.
        StartActivity(typeof(Activity1));
    }
}

活动的的OnCreate()上,因此在UI线程调用<$ C $执行C> Thread.sleep代码()里面会锁定在主线程,可能生成应用程序无响应(ANR)是显示给用户。

The OnCreate() method of an Activity is executed on the UI thread therefore calling a Thread.Sleep() inside it will lock up the main thread, possibly generating an Application Not Responding (ANR) to be display to the user.

这是错误的Xamarin文档,您不该运行 Thread.sleep代码()在UI线程上,尤其是在一核心生命周期回调的活动。

This is fault in the Xamarin docs, you should not run a Thread.Sleep() on the UI thread, especially within one of the core lifecycle callbacks for an activity.

通过使用一个后台线程来执行睡眠,然后回调到飞溅活动启动下一个活动修复此:

Fix this by using a background thread to execute the sleep and then call back into the splash activity to launch the next activity:

[Activity(Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        System.Threading.Tasks.Task.Run( () => {
            Thread.Sleep(10000); // Simulate a long loading process on app startup.
            StartActivity(typeof(Activity1));
        });
    }
}

这篇关于Xamarin闪屏的例子并不在横向模式下的手机上运行。如何解决呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆