簡體   English   中英

在Xamarin Android中,啟動畫面速度太慢

[英]Splash screen too slow in Xamarin Android

我正在創建一個顯示啟動畫面的應用程序,然后創建主要活動。 我正在按照這個看起來非常簡單的教程: https//developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/

在實現之后,我可以成功地看到飛濺,但有時(20個中的1個)使用S5我看到以下屏幕:

屏幕錯了

接下來是(右)啟動(從模擬器中獲取但只是為了說明我的觀點):

在此輸入圖像描述

所以我的猜測是,有時Xamarin需要很長時間來加載應用程序,因此它有延遲顯示飛濺。 有什么方法可以阻止這種情況嗎?

更新1我已經按照教程,但我為此刪除了睡眠:

Insights.Initialize ("<APP_KEY>", Application.Context);
StartActivity(typeof (MainActivity));

該示例調用Thread.Sleep(10000); 在UI線程上... 這將鎖定應用程序並生成ANR

通過后台睡眠然后觸發下一個活動來修復它:

namespace SplashScreen
{
    using System.Threading;

    using Android.App;
    using Android.OS;

    [Activity(Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true)]
    public class SplashActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Task.Run (() => {
                Thread.Sleep (10000); // Simulate a long loading process on app startup.
                RunOnUiThread (() => { 
                    StartActivity (typeof(Activity1));
                });
            });
        }
    }
}

即使這篇文章相當陳舊,我在實現SplashScreen時也有類似的經驗,可以通過更新SplashScreen的樣式/主題來解決這個問題。 @frederico m rinaldi有時看到的屏幕通常是使用Android的默認(Holo)主題創建的。

雖然你沒有提供應用於SplashScreen的樣式(參見Theme = @style/Theme.Splash接受答案 ), Theme = @style/Theme.Splash是我的。 也許你可以檢查它們是否不同。

<style name="Theme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
  <!-- Use a fully opaque color as background. -->
  <item name="android:windowBackground">@android:color/black</item>
  <!-- This removes the title bar seen within the first screen. -->
  <item name="windowNoTitle">true</item>
  <!-- Let the splash screen use the entire screen space by enabling full screen mode -->
  <item name="android:windowFullscreen">true</item>
  <!-- Hide the ActionBar (Might be already defined within the parent theme) -->
  <item name="windowActionBar">false</item>
</style>

您可能會注意到我只使用黑色作為背景,因為我的SplashScreen使用自定義布局文件而不是靜態圖像( this.SetContentView(Resource.Layout.SplashScreen); )。 此外,加載圖像( drawable )可能需要一些時間,這可能是您可以看到默認主題而不是啟動畫面的主要原因。 此外,我省略了某些屬性的android: XML命名空間,這是由於Google內部實現了Android支持庫功能。

請注意,為了使用AppCompat主題,您的應用程序必須包含AppCompat支持庫,並且您的Activity必須是子類Android.Support.V7.App.AppCompatActivity子類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM