繁体   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