public void CallApi(string code) { progressbar.Visibility = ViewStates.Visible; contentWebview.Visibility = ViewStates.Gone; Task.Factory.StartNew(() => { var response = ApiService.PostGetToken(code); if (!response.Result.IsSuccess) { mActivity.RunOnUiThread(() => { progressbar.Visibility = ViewStates.Gone; contentWebview.Visibility = ViewStates.Visible; AlertDialog.Builder dialog = new AlertDialog.Builder(mActivity); AlertDialog alert = dialog.Create(); alert.SetTitle("ALERTA"); alert.SetMessage("Hubo un error inesperado"); alert.SetButton("ACEPTAR", (c, ev) => { }); alert.SetButton2("CANCEL", (c, ev) => { }); alert.Show(); }); } var access_token = ((GetTokenResponse)response.Result.Result).access_token; //GetClient /*Init: Creating object to request*/ var header = new Models.Request.Client.Header { token = access_token, }; var datum = new Models.Request.Client.Datum { header = header, }; var requestModel = new Models.Request.Client.getClientRequest { data = new List <Models.Request.Client.Datum>() }; requestModel.data.Add(datum); /*Finish: Creating object to request*/ var ResponseClientInfo = ApiService.GetClientInfo( access_token, Constants.Url.GetClientServicePrefix, requestModel).Result; if (!ResponseClientInfo.IsSuccess) { mActivity.RunOnUiThread(() => { progressbar.Visibility = Android.Views.ViewStates.Gone; Android.App.AlertDialog.Builder dialog = new AlertDialog.Builder(mActivity); AlertDialog alert = dialog.Create(); alert.SetTitle("Lo sentimos"); alert.SetMessage("Su autenticación ha fallado"); alert.SetButton("ACEPTAR", (c, ev) => { var intent2 = new Intent(mActivity, typeof(MainActivity)); mActivity.StartActivity(intent2); mActivity.Finish(); }); alert.SetButton2("CANCEL", (c, ev) => { mActivity.Finish(); }); alert.Show(); return; }); } mActivity.RunOnUiThread(() => { progressbar.Visibility = Android.Views.ViewStates.Gone; contentWebview.Visibility = Android.Views.ViewStates.Visible; }); var Client = (Models.Responses.Client.getClientResponse)ResponseClientInfo.Result; mActivity.RunOnUiThread(() => { Intent intent = new Intent(mActivity, typeof(HomeActivity)); intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop); intent.PutExtra("ClientInfo", JsonConvert.SerializeObject(Client)); intent.PutExtra("token", access_token); mActivity.StartActivity(intent); mActivity.Finish(); }); }); }