Hi,
I have two activities (SplashActivity, MainActivity) that i am trying to transition between but i get a black screen, and what seems like a complete restart, between them.
The reason i'm using a second activity for the splash screen is for an animation.
Is there a way to start loading the MainActivity while the SplashActivity displays its animation? As it currently stands, MainActivity only begins after the SplashActivity, defeating the whole purpose.
Code snippets of the 2 activities below:
SplashActivity
[Activity(Label = "IFS.Mobile", Icon = "@mipmap/icon", Theme = "@style/SplashTheme", NoHistory = true, MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] public class OnboardingWithCenterAnimationActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity { public static int STARTUP_DELAY = 300; public static int ANIM_ITEM_DURATION = 1000; public static int ITEM_DELAY = 300; static readonly string TAG = "X:" + typeof(OnboardingWithCenterAnimationActivity).Name; private bool animationStarted = false; protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Log.Debug(TAG, "SplashActivity.OnCreate"); SetContentView(Resource.Layout.activity_onboarding_center); Task.Run(() => { Log.Debug(TAG, "Pausing Thread"); Thread.Sleep(2000); RunOnUiThread(() => { Log.Debug(TAG, "Starting MainActivity"); StartActivity(typeof(MainActivity)); }); }); } // Prevent the back button from canceling the startup process public override void OnBackPressed() { } public override void OnWindowFocusChanged(bool hasFocus) { if (!hasFocus || animationStarted) { return; } animate(); base.OnWindowFocusChanged(hasFocus); }
MainActivity
[Activity(Label = "IFS.Mobile", Icon = "@mipmap/icon", Theme = "@style/MainTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Initialize Xamarin Forms engines. Xamarin.Forms.Forms.Init(this, bundle); CrossCurrentActivity.Current.Init(this, bundle); TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; LoadApplication(new App(new AndroidPlatformInitializer())); } }
Posts
Anyone?