Reputation: 255
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();
}
}
Upvotes: 1
Views: 1863
Reputation: 377
Maybe no the solution in your case but in my case it works.
I just created a clean Xamarin app an added a SplashScreen to it using the steps from Microsoft web site.
It works but a black screen appears after splash screen and before app load (sometimes it takes several seconds in this).
Following the answered question in MSDN Xamarin Forms 10 seconds black screen after Splash Screen
The solution was to add <item name="android:windowIsTranslucent">true</item>
to the style of the main activity theme. Then my style.xml
file ends like this:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
<item name="android:windowIsTranslucent">true</item> <!--Add this line-->
</style>
<style name="MyTheme.Base" parent="Theme.AppCompat.Light">
</style>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<style name="MyTheme.Splash" 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>
</style>
</resources>
Upvotes: 0
Reputation: 10958
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://learn.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();
}
}
Upvotes: 1
Reputation: 9671
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
Upvotes: 1
Reputation: 48
your task delay says "3000" which means it'll take 3 seconds, lower down to "1000" and see if it helps
Upvotes: 0