Forum Xamarin.Android
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.

Between loading my Mainpage and Splash Screen, there is white screen occurring on Xamarin.Android

pelinalpppelinalpp Member ✭✭✭
edited October 9 in Xamarin.Android

I have a Xamarin.Forms app that has splash screen for ios and android. It works on ios perfectly. But I have a problem on android. The problem is: splash screen launches, after that between loading my Mainpage and splash screen, there is white screen occurring. The problem is like this:

I did a sample project for this problem.

Where is my problem?
Thank you in advance.

Best Answers

  • jezhjezh Member, Xamarin Team Xamurai
    Accepted Answer

    There is a similar thread about this, you can check it here: https://forums.xamarin.com/discussion/19362/xamarin-forms-splashscreen-in-android

  • pelinalpppelinalpp Member ✭✭✭
    edited October 13 Accepted Answer

    Best approach works in this link: https://xamarinhelp.com/creating-splash-screen-xamarin-forms/

    So I set MainActivity Theme as splashscreen (Theme = "@style/splashscreen"). And I changed theme in MainActivity OnCreate method in this way:

    protected override void OnCreate(Bundle bundle)
    {
        base.Window.RequestFeature(WindowFeatures.ActionBar);
        // Name of the MainActivity theme you had there before.
        // Or you can use global::Android.Resource.Style.ThemeHoloLight
        base.SetTheme(Resource.Style.MainTheme);
    
        base.OnCreate(bundle);
    
        ...
     }
    

    This worked. Thank you @jezh for the guidance, I found solution on your sent link.

    It took me a long time to find this. Because I had another problem. But firstly I thought two problems were caused by the splash screen.

    My second problem is: I have permission (read/write/camera) on my main app. And I have got these permissions with this way on my mainactivity:
    ActivityCompat.RequestPermissions(this, all_permissions, RequestId);

    This causes the black screen after the splash screen on some android devices (After I solve white screen issue with above solution, I encounter with black screen issue. And I thought both of them were caused by the splash screen.) I realized afterwards that permissions cause this issue. And I solved this problem with did async the permission. It didn't solve completely black screen problem, but the time the black screen appears has decreased.

    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
       protected override void OnCreate(Bundle savedInstanceState)
       {
        //...
        RequestPermissions();
       }
    
       private async void RequestPermissions()
       {
        await Task.Yield();
        ActivityCompat.RequestPermissions(this, all_permissions, RequestId);
       }
    }
    

    Maybe it will be useful another one.

Answers

  • HamittirpanHamittirpan Member ✭✭✭✭
    edited October 9

    Hi @pelinalpp

    Have you deploy on real device and try? This may be due to emulator performance differences.
    Also, if you are using too many nuget packages in the project, their initialization also increases this waiting period.

  • HamittirpanHamittirpan Member ✭✭✭✭

    Hi @pelinalpp

    Also, I suggest you check this link. It looks like it will solve your problem.

    https://stackoverflow.com/a/61603106

  • pelinalpppelinalpp Member ✭✭✭

    Yes @Hamittirpan, above gif is from real device.
    And there is not too many nuget packages on sample project, But it has same issue.

  • pelinalpppelinalpp Member ✭✭✭

    @Hamittirpan said:
    Hi @pelinalpp

    Also, I suggest you check this link. It looks like it will solve your problem.

    https://stackoverflow.com/a/61603106

    I tried this but when I add NoAnimation Flag to main activity intent on Splash screen class, the app works first but after a few seconds debug mode shuts down. And It also doesn't solve white screen problem.

  • pelinalpppelinalpp Member ✭✭✭

    Actually I understand problem. Problem is: MainTheme has not splash screen but MainActivity Theme is MainTheme. But I don't know how can I fix this.
    I tried to add splash screen to MainTheme or I tried to set MainActivity Theme is splashscreen. But these didn't work.

  • jezhjezh Member, Xamarin Team Xamurai
    Accepted Answer

    There is a similar thread about this, you can check it here: https://forums.xamarin.com/discussion/19362/xamarin-forms-splashscreen-in-android

  • pelinalpppelinalpp Member ✭✭✭
    edited October 9

    @jezh thank you.
    Yes last comment that is LearnEverything's comment works. But when I apply this solution, MainPage background also changes as splash screen. How can I set only splash screen? Or Should I clean MainPage background? If I should clean MainPage background, how?

  • jezhjezh Member, Xamarin Team Xamurai

    You just need to apply this style for your splash screen.

  • pelinalpppelinalpp Member ✭✭✭

    It doesn't work when I just apply this style for my splash screen. Again occurs white screen.
    But I want to be sure. You mean apply this style to my splash screen, don't you?

    <!--Splash-->
        <item name="android:windowBackground">@drawable/splash_screen</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
    

    If you mean that, I already did this on sample project and it doesn't work.

  • pelinalpppelinalpp Member ✭✭✭
    edited October 13 Accepted Answer

    Best approach works in this link: https://xamarinhelp.com/creating-splash-screen-xamarin-forms/

    So I set MainActivity Theme as splashscreen (Theme = "@style/splashscreen"). And I changed theme in MainActivity OnCreate method in this way:

    protected override void OnCreate(Bundle bundle)
    {
        base.Window.RequestFeature(WindowFeatures.ActionBar);
        // Name of the MainActivity theme you had there before.
        // Or you can use global::Android.Resource.Style.ThemeHoloLight
        base.SetTheme(Resource.Style.MainTheme);
    
        base.OnCreate(bundle);
    
        ...
     }
    

    This worked. Thank you @jezh for the guidance, I found solution on your sent link.

    It took me a long time to find this. Because I had another problem. But firstly I thought two problems were caused by the splash screen.

    My second problem is: I have permission (read/write/camera) on my main app. And I have got these permissions with this way on my mainactivity:
    ActivityCompat.RequestPermissions(this, all_permissions, RequestId);

    This causes the black screen after the splash screen on some android devices (After I solve white screen issue with above solution, I encounter with black screen issue. And I thought both of them were caused by the splash screen.) I realized afterwards that permissions cause this issue. And I solved this problem with did async the permission. It didn't solve completely black screen problem, but the time the black screen appears has decreased.

    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
       protected override void OnCreate(Bundle savedInstanceState)
       {
        //...
        RequestPermissions();
       }
    
       private async void RequestPermissions()
       {
        await Task.Yield();
        ActivityCompat.RequestPermissions(this, all_permissions, RequestId);
       }
    }
    

    Maybe it will be useful another one.

Sign In or Register to comment.