async void onSubmitButtonClicked(object sender, EventArgs e) { if (userAnswer != "") { activityIndicator.IsVisible = true; activityIndicator.IsRunning = true; string jsonsurvey = JsonConvert.SerializeObject(survey); string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostSurveyAnswers(jsonsurvey, userSession.username)); while (httpTask == null) { httpTask = await Task.Run <string>(() => HttpRequestHandler.PostSurveyAnswers(jsonsurvey, userSession.username)); } string httpResult = httpTask.ToString(); if (httpTask != null) { activityIndicator.IsVisible = false; activityIndicator.IsRunning = false; if (httpResult == "Successfully submitted survey. Thank you for participating!") { await DisplayAlert("Success", "Successfully submitted survey. Thank you for participating!", "OK"); } else { await DisplayAlert("Error", httpResult, "OK"); } var page = App.Current.MainPage as rootPage; var surveyList = new surveyList(); page.changePage(surveyList); } } else { await DisplayAlert("Error", "Please select an answer", "OK"); } }