Current style guides don’t recommend displaying a splash screen on app start, but encourage to speed up the app start as much as possible. Nonetheless, you might want to show a so-called launch image while certain preparation needs to be performed in the background. On iOS it is rather trivial to do so. On Android we will need to use some kind of workaround, since launch images are usually not supported.
iOS
On iOS the procedure is similar to the app icon. We prepare the launch image in three different sizes, possibly using the following script.
#!/bin/bash
for size in 320x480 640x960 640x1136
do
convert xamarin.png -resize $size\> -background black -gravity center -extent $size launch$size.png
done Then we set them as launch images within the iOS project options → Build → iOS Application → Universal Launch Images.
Android
On Android we need to display an image before LoadApplication is called. One possibility is to add a new “LaunchActivity” to the Android project:
[Activity(
Label = "Icons",
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
MainLauncher = true,
Theme = "@android:style/Theme.NoTitleBar")]
public class LaunchActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
}
protected override async void OnResume()
{
base.OnResume();
await Task.Run(() => Thread.Sleep(10));
StartActivity(typeof(MainActivity));
}
}
Note the MainLauncher attribute: It causes the LaunchActivity to be the first activity when starting the app. (Make sure to remove this attribute in “MainActivity.cs”.) The activity simply displays a layout stored in “Resources/layout/Main.axml”, referring to the “android.png” image stored in “Resources/drawable”:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/launchImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/xamarin"
android:scaleType="centerInside" />
</LinearLayout>
As soon as the activity becomes visible to the user, it triggers the MainActivity to be started. The tiny delay of something like 10 milliseconds makes sure that the launch image is actually drawn before continuing with the next activity. The image will remain visible until the MainActivity is loaded, which is usually much longer than 10 milliseconds.