protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Detect if there is network connection

            ConnectivityManager connectivityManager = (ConnectivityManager)GetSystemService(ConnectivityService);
            NetworkInfo         activeConnection    = connectivityManager.ActiveNetworkInfo;
            bool isOnline = (activeConnection != null) && activeConnection.IsConnected;

            var phoneState = new PrimusFlex.Mobile.Common.PhoneState((TelephonyManager)GetSystemService(TelephonyService));
            var imei       = phoneState.IMEI();

            if (isOnline)
            {
                // if phome IMEI already is saved try to login by(phone)IMEI

                if (TryToLoginByIMEI(imei))
                {
                    Intent homeActivity = new Intent(this, typeof(HomeActivity));
                    homeActivity.PutExtra("access_token", access_token);
                    homeActivity.PutExtra("user_name", userName);
                    StartActivity(homeActivity);
                }
                else
                {
                    // Go to Login activity

                    Intent loginActivity = new Intent(this, typeof(LoginActivity));
                    StartActivity(loginActivity);
                }
            }
            else
            {
                // Go to OfflineHome activity

                Intent offlineHomeActivity = new Intent(this, typeof(OfflineHomeActivity));
                StartActivity(offlineHomeActivity);
            }

            Finish();
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Login);


            var btnLogin = this.FindViewById <Button>(Resource.Id.btnLogin);

            btnLogin.Click += async(sender, e) =>
            {
                FindViewById <TextView>(Resource.Id.textViewErrorMessage).Visibility = ViewStates.Gone;
                // start loading circle image (progress bar)
                var progressBarCircle = FindViewById <ProgressBar>(Resource.Id.progressBarCircle);
                progressBarCircle.Visibility = ViewStates.Visible;

                var    userName = this.FindViewById <EditText>(Resource.Id.editTextUserName).Text;
                var    password = this.FindViewById <EditText>(Resource.Id.editTextPassword).Text;
                string url      = Constant.TokenRequestUrl;

                var activity = await Authentication.Start(this, url, userName, password);

                if (activity != null)
                {
                    // save phone imei for next time login

                    string imei         = new PrimusFlex.Mobile.Common.PhoneState((TelephonyManager)GetSystemService(TelephonyService)).IMEI();
                    var    access_token = activity.GetStringExtra("access_token");
                    SavePhone(imei, access_token);

                    // start activity

                    StartActivity(activity);
                }
            };
        }