Search code examples
c#xamarin.formssplash-screen

Xamarin Forms 10 seconds black screen after Splash Screen


At first I should say that I have read all similar questions and they can not solve my problem .

I have a Splash Screen in my Xamarin Forms project and check the credentials in it and then in each condition start Main Activity with different parameter toward the condition . When Splash Screen finish it's work and disappear , the app show a black screen about 10 seconds and then main page is showing

this is my Splash :

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

and this is my 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));
        }
    }

How can I fix this ?


Solution

  • Thanks to @LeonLu-MSFT I add this code in style.xml without any change in MainActivity and Spalsh Screen

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

    I don't have Mac and ios device to test in ios