Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xamarin在闪屏后形成10秒黑屏_C#_Xamarin.forms_Splash Screen - Fatal编程技术网

C# Xamarin在闪屏后形成10秒黑屏

C# Xamarin在闪屏后形成10秒黑屏,c#,xamarin.forms,splash-screen,C#,Xamarin.forms,Splash Screen,首先,我应该说,我读过所有类似的问题,它们不能解决我的问题 我在Xamarin Forms项目中有一个启动屏幕,检查其中的凭据,然后在每个条件下使用不同的参数启动主活动。当启动屏幕完成工作并消失时,应用程序会显示一个约10秒的黑屏,然后显示主页 这是我的飞溅: [Activity(Theme = "@style/MainTheme.Splash", MainLauncher = true, NoHistory = tru

首先,我应该说,我读过所有类似的问题,它们不能解决我的问题

我在Xamarin Forms项目中有一个启动屏幕,检查其中的凭据,然后在每个条件下使用不同的参数启动主活动。当启动屏幕完成工作并消失时,应用程序会显示一个约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);
        }
这是我的主要活动:

[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));
        }
    }

如何修复此问题?

多亏了@LeonLu MSFT,我在style.xml中添加了此代码,而没有对MainActivity和Spalsh屏幕进行任何更改

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

我没有Mac和ios设备在ios中进行测试

什么是“一些代码…”?@AlessandroCaliaro从Rest API和SecureStorages获取数据可能需要一些时间…@AlessandroCaliaro当然需要一些时间,但在更改活动之前。当活动发生更改时,屏幕变为黑色。如果从Rest API和SecureStorage获取数据需要花费时间,您还可以在android
styles.xml
中添加
true
,则在切换页面时,屏幕将不会显示黑色。