I presume the issues is connected with the fact that you are trying to start the already started SingleTop
activity for the second time.
However, the recommendation is to write a splash screen a bit differently - without needing separate activity. See this nice blog post by Adam Pedley on splash screen implementation in Xamarin.Forms.
Instead of having a separate activity, you can just temporarily apply a "splash" theme to the main activity, before the activity loads. This is useful, because it makes your app load faster than having a full separate splash screen activity.
Create a style in Resources/values/styles.xml
:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="splashscreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splashscreen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
<resources>
Set this theme to the MainActivity
via attribute:
[Activity(Label = "Mobile App",
Theme = "@style/splashscreen",
Icon = "@drawable/icon",
MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize |
ConfigChanges.Orientation,
LaunchMode = LaunchMode.SingleTop)]
public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
And then override the OnCreate
method to set the actual theme back:
protected override void OnCreate(Bundle bundle)
{
base.Window.RequestFeature(WindowFeatures.ActionBar);
// For global use "global::" prefix - global::Android.Resource.Style.ThemeHoloLight
base.SetTheme(Resource.Style.MainTheme);
base.OnCreate(bundle);
...
}