Creating a splash screen

In an Xamarin android application the splash screen provides an important role in an application. It is the first startup page when an application start which gives the information about the application.

The splash screen should me more attractive and should be informative so that the user can attract and get the information about an applicatio. The splash screen holds in the screen for some second.

[Activity(Theme = "@style/Theme.Splash", Label = "MANDDO", MainLauncher = true, NoHistory = true, ScreenOrientation = ScreenOrientation.Portrait)]
    public class SplashActivity : Activity
    {
       
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
           // SetContentView(Resource.Layout.Splash);
            // Create your application here.

           
            ISharedPreferences prefs = Application.Context.GetSharedPreferences("PREF_NAME", FileCreationMode.Private);
            //LoadAnimatedGif();
            Int64 username = Convert.ToInt64(prefs.GetString("userid", "0"));
            string password = prefs.GetString("userloginpass", "");
            string tutorialsPageValues = prefs.GetString("tutorialsPageValue", "");
            if (username != 0 && password != null)
            {
                this.StartActivity(typeof(MainActivity));
            }
            else
            {
                this.StartActivity(typeof(LoginSignUpActivity));
            }
            //this.StartActivity(typeof(LoginActivity));
        }

    }


If you want to hold the screen for Example 3 sec and want to create the custom layout:

        System.Timers.Timer t;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Splash);
            t = new System.Timers.Timer();
            t.Interval = 3000;
            t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);
            t.Start();
           // System.Threading.Thread.Sleep(10000); //Let's wait awhile...
        }

        protected void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            t.Stop();
           
            ISharedPreferences prefs = Application.Context.GetSharedPreferences("PREF_NAME", FileCreationMode.Private);
            Int64 username = Convert.ToInt64(prefs.GetString("userid", "0"));
            string password = prefs.GetString("userloginpass", "");
            string tutorialsPageValues = prefs.GetString("tutorialsPageValue", "");
            if (username != 0 && password != null)
            {
                this.StartActivity(typeof(MainActivity));
                this.Finish();
            }
            else
            {
                this.StartActivity(typeof(LoginSignUpActivity));
                this.Finish();
            }

        }

No comments:

Post a Comment