Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Splash Screen on Android is Blank

SaoryEmanoelleSaoryEmanoelle USMember ✭✭
edited March 27 in Xamarin.Forms

Good afternoon! How are you all?

I've been trying to implement a splash screen all day following tutorials here and there. The most common solution I found was to have a XML file in the drawable folder and call a bitmap from there. It was working fine until I tried to add a different splash for landscape. It all went downhill from there.

So I found another solution: To set the content view of my SplashActivity to an XML where I set a layout and an Image. It works perfectly for portrait and landscape in preview mode. However, when I run the app, the splash screen is nowhere to be found and it only shows a blank screen.

This is my Splash Activity.

Its XML file is:

Strangely enough, when I put the SetContentView in my MainActivity it shows in there (Even though not correctly sized) so I don't think the problem is in the XML file. I really don't know what else I could try to solve this :(

Best Answer

  • LandLuLandLu Member, Xamarin Team Xamurai
    Accepted Answer

    OnResume will be called immediately after OnCreate. You don't set enough time to display the splash page. Try the code below:

    [Activity(Label = "SplashActivity", MainLauncher = true)]
    public class SplashActivity : Activity
    {
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
    
            // Create your application here
            SetContentView(Resource.Layout.splash_layout);
    
            await Task.Delay(3000);
            var intent = new Intent(this, typeof(MainActivity));
            StartActivity(intent);
        }
    }
    

    Adjust the delay as you want there.

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai
    Accepted Answer

    OnResume will be called immediately after OnCreate. You don't set enough time to display the splash page. Try the code below:

    [Activity(Label = "SplashActivity", MainLauncher = true)]
    public class SplashActivity : Activity
    {
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
    
            // Create your application here
            SetContentView(Resource.Layout.splash_layout);
    
            await Task.Delay(3000);
            var intent = new Intent(this, typeof(MainActivity));
            StartActivity(intent);
        }
    }
    

    Adjust the delay as you want there.

  • SaoryEmanoelleSaoryEmanoelle USMember ✭✭

    Oh my, I tried so many things but turns out the solution was so much simpler than I thought! Thank you so much, it worked :)

Sign In or Register to comment.