White screen after splash screen
When I put the splash screen in my app, then a white screen appears and then the main screen.
I realized that it is the white screen the background my app that shows it for two seconds and then enters the main screen.
I wanted to know if there is a way to delete this page or make it last zero second?
Thanks to those who answer me!
this code is my splash screen:
[Activity(Label = "myapp", MainLauncher = true, Theme = "@style/Theme.Splash", NoHistory = true)]
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
}
protected override void OnResume()
{
base.OnResume();
Task splashwork = new Task(async () => { await Task.Delay(3000); });
splashwork.ContinueWith(h =>
{
StartActivity(new Intent(Application.Context, typeof(MainActivity)));
TaskScheduler.FromCurrentSynchronizationContext();
});
splashwork.Start();
}
}
You could use two activities. One activity is used to show the splash screen and the other used to show the mian activity.
You could check the sample code i done before. Android specific animations Xamarin.Forms - Splash screen
Updated:
Create a Splash Screen. https://docs.microsoft.com/en-us/xamarin/android/user-interface/splash-screen
Create a splash_screen.xml in drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/splash_background"/>
</item>
<item>
<bitmap
android:src="@drawable/splash_logo"
android:tileMode="disabled"
android:gravity="center"/>
</item>
</layer-list>
Add specifial color in Resources/values/colors.xml.
<?xml version="1.0" encoding="utf-8"?>
<resources>
...
<color name="splash_background">#FFFFFF</color>
</resources>
Create a Theme in Resources/values/styles.xml
<style name="Theme_SplashScreen" parent ="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionBar">true</item>
Load the splash screen in Activity_SplashScreen activity.
[Activity(Label = "Activity_SplashScreen", Theme = "@style/Theme_SplashScreen", MainLauncher = true)]
public class Activity_SplashScreen : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
}
protected override void OnResume()
{
base.OnResume();
Task startupWork = new Task(() => { SimulateStartup(); });
startupWork.Start();
}
// Simulates background work that happens behind the splash screen
async void SimulateStartup()
{
await Task.Delay(3000); // Simulate a bit of startup work.
StartActivity(new Intent(Application.Context, typeof(Activity_Screen)));
}
}
Activity_Screen activity:
[Activity(Label = "Activity_Screen")]
public class Activity_Screen : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
SetContentView(Resource.Layout.layout_Screen);
Toast.MakeText(this, "Welcome to MainActivity", ToastLength.Long).Show();
}
}
This is a known issue of Xamarin Forms targeting Android 10 while using NavigationPage
as a wrapper of the main page, it is still not fixed by XF development team you can follow it progress/status on [Bug] White Screen in Android when using NavigationPage