簡體   English   中英

Xamarin 在啟動畫面后 10 秒形成黑屏

[英]Xamarin Forms 10 seconds black screen after Splash Screen

起初我應該說我已經閱讀了所有類似的問題,但它們無法解決我的問題。

我的 Xamarin Forms 項目中有一個啟動畫面,並檢查其中的憑據,然后在每個條件中使用不同的參數啟動 Main Activity 。 當啟動畫面完成它的工作並消失時,應用程序顯示黑屏約 10 秒,然后顯示主頁

這是我的飛濺:

[Activity(Theme = "@style/MainTheme.Splash",
              MainLauncher = true,
              NoHistory = true,
              ScreenOrientation = ScreenOrientation.Portrait)]
    public class SplashActivity : Activity
    {
        static readonly string TAG = "X:" + typeof(SplashActivity).Name;
        public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
        {
            base.OnCreate(savedInstanceState, persistentState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            Log.Debug(TAG, "SplashActivity.OnCreate");
        }

        protected override void OnResume()
        {
            base.OnResume();
            Task startupWork = new Task(() => { SimulateStartup(); });
            startupWork.Start();
        }

        async void SimulateStartup()
        {
            Some Code ...
            InvokeMainActivity("SomeType");
        }

        private void InvokeMainActivity(string type)
        {
            Intent _activity = new Intent(Application.Context, typeof(MainActivity));
            _activity.PutExtra("Key", type);
            _activity.AddFlags(ActivityFlags.NoAnimation);
            StartActivity(_activity);
        }

這是我的 MainActivity :

[Activity(Label = "@string/app_name",
        Icon = "@drawable/icon",
        Theme = "@style/MainTheme",
        MainLauncher = false,
        LaunchMode = LaunchMode.SingleTask,
        ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.Locale | ConfigChanges.LayoutDirection)
        ]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override async void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            Xamarin.Essentials.Platform.Init(this, bundle);
            Rg.Plugins.Popup.Popup.Init(this, bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);

            FFImageLoading.Forms.Platform.CachedImageRenderer.Init(enableFastRenderer: true);

            Window.DecorView.LayoutDirection = LayoutDirection.Rtl;

            string type = Intent.GetStringExtra("SomeType");

            LoadApplication(new App(type));
        }
    }

我怎樣才能解決這個問題 ?

首先,我應該說我已經閱讀了所有類似的問題,但它們不能解決我的問題。

我在Xamarin Forms項目中有一個啟動畫面,並檢查其中的憑據,然后在每種情況下使用針對該條件的不同參數啟動Main Activity。 啟動畫面完成后,它消失並消失,該應用程序顯示黑屏約10秒鍾,然后顯示主頁

這是我的飛濺:

[Activity(Theme = "@style/MainTheme.Splash",
              MainLauncher = true,
              NoHistory = true,
              ScreenOrientation = ScreenOrientation.Portrait)]
    public class SplashActivity : Activity
    {
        static readonly string TAG = "X:" + typeof(SplashActivity).Name;
        public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
        {
            base.OnCreate(savedInstanceState, persistentState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            Log.Debug(TAG, "SplashActivity.OnCreate");
        }

        protected override void OnResume()
        {
            base.OnResume();
            Task startupWork = new Task(() => { SimulateStartup(); });
            startupWork.Start();
        }

        async void SimulateStartup()
        {
            Some Code ...
            InvokeMainActivity("SomeType");
        }

        private void InvokeMainActivity(string type)
        {
            Intent _activity = new Intent(Application.Context, typeof(MainActivity));
            _activity.PutExtra("Key", type);
            _activity.AddFlags(ActivityFlags.NoAnimation);
            StartActivity(_activity);
        }

這是我的MainActivity:

[Activity(Label = "@string/app_name",
        Icon = "@drawable/icon",
        Theme = "@style/MainTheme",
        MainLauncher = false,
        LaunchMode = LaunchMode.SingleTask,
        ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.Locale | ConfigChanges.LayoutDirection)
        ]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override async void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            Xamarin.Essentials.Platform.Init(this, bundle);
            Rg.Plugins.Popup.Popup.Init(this, bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);

            FFImageLoading.Forms.Platform.CachedImageRenderer.Init(enableFastRenderer: true);

            Window.DecorView.LayoutDirection = LayoutDirection.Rtl;

            string type = Intent.GetStringExtra("SomeType");

            LoadApplication(new App(type));
        }
    }

我怎樣才能解決這個問題 ?

我也面臨類似的問題。 我通過添加修復它

<item name="android:windowIsTranslucent">true</item>

在 ~\\Resources\\values\\styles.xml 中。

因此,如果您遇到類似的問題,請按照以下屏幕截圖添加它,希望它也適用於您:

在此處輸入圖片說明

暫無
暫無

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

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