Skip to content

Instantly share code, notes, and snippets.

@angusbreno
Created August 1, 2016 17:51
Show Gist options
  • Save angusbreno/5626decb9f917e238b0d16a4355906b5 to your computer and use it in GitHub Desktop.
Save angusbreno/5626decb9f917e238b0d16a4355906b5 to your computer and use it in GitHub Desktop.
Splash Activity Recipe On Xamarin Forms
<!-- Put this on 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/primary"/>
<!--@color/primary-->
</item>
<item>
<bitmap
android:src="@drawable/applogoimage"
android:tileMode="disabled"
android:adjustViewBounds="true"
android:gravity="center"/>
</item>
</layer-list>
[Activity(
Label = "YourAppName",
//Theme = "@style/AppTheme.Splash",
MainLauncher = true, /////PUT THIS TO FALSE ON MAIN ACTIVITY
NoHistory = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation
)]
public class SplashActivity : AppCompatActivity
{
static readonly string TAG = "X:" + typeof(SplashActivity).Name;
public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
{
base.OnCreate(savedInstanceState, persistentState);
Log.Debug(TAG, "SplashActivity.OnCreate");
}
protected override void OnResume()
{
base.OnResume();
Task startupWork = new Task(() =>
{
Log.Debug(TAG, "Performing some startup work that takes a bit of time.");
Log.Debug(TAG, "Working in the background - important stuff.");
});
startupWork.ContinueWith(t =>
{
Log.Debug(TAG, "Work is finished - start Activity1.");
var MainIntent = new Intent(Application.Context, typeof(MainActivity));
try
{
Log.Debug("CCCCCCCCCCCCCCCCCCCCCCC", Intent.GetStringExtra("notificationId"));
string notificationId = Intent.Extras.GetString("notificationId");
MainIntent.PutExtra("notificationId", Intent.GetStringExtra("notificationId"));
Intent.RemoveExtra("notificationId");
}
catch (System.Exception)
{
}
StartActivity(MainIntent);
}, TaskScheduler.FromCurrentSynchronizationContext());
startupWork.Start();
}
<style name="AppTheme.Splash">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment