I am viewing an article on Xamarin that guides how we can add a Splash Screen on an AppCompatActivity. Whenever I run the application it forces my device to restart.
Here is what I have done to get the issue solved and I was failed.
Still the issue is there. Here is my code for it maybe I am doing something wrong in the coding part.
Splash Activity
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Support.V7.App;
using Android.Views;
using Android.Widget;
namespace TestApp
{
[Activity(Label = "SplashActivity", MainLauncher = true, NoHistory = true, Theme = "@style/MyTheme.Splash")]
public class SplashActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
var startupTask = new Task(SimulateStartup);
startupTask.Start();
}
private async void SimulateStartup()
{
await Task.Delay(4000);
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);
StartActivity(intent);
}
}
}
MainActivity
using System.Threading.Tasks;
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Support.V7.App;
using System;
using Android.Content;
namespace TestApp
{
[Activity(Label = "MainActivity")]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
}
}
}
Styles.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<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>
</style>
</resources>
splash_screen.xml
<?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" android:tileMode="disabled" android:gravity="center" />
</item>
</layer-list>
colors.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<color name="primary">#4682b4</color>
<color name="primaryDark">#2c6493</color>
<color name="accent">#FFC107</color>
<color name="window_background">#F5F5F5</color>
<color name="splash_background">#4682b4</color>
</resources>
Please check your bitmap size. If it is too big it may cause a reboot: see Xamarin Android App causes device reboot