Reputation: 506
I have two projects in one solution. Core and Droid. In Droid project I have a method that need to be called when async method IN CORE finishes its task. My code in Core is:
public async Task<bool> UsersAuthenTask(string email, string password, Action<Intent> startActivityDroid, Intent intent)
{
var httpClient = GetHttpClient(email, password);
//var response = await httpClient.GetAsync(UsersAuth.ClientsApiBaseUri + email + "password="+password).ConfigureAwait(false);
var response = await httpClient.GetAsync(UsersAuth.ClientsApiBaseUri).ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
startActivityDroid(intent);
}
else
{
//I NEED TO START METHOD FROM DROID HERE
}
return false;
}
I need to call method "AuthorizationFailed" that is placed in Droid:
login.Click += delegate
{
activityIndicator.Visibility = Android.Views.ViewStates.Visible;
new UsersAuthentication().UsersAuthenTask(email.Text,password.Text, StartActivity, new Intent(this, typeof(IndMassActivity)));
};
}
public void AuthorizationFailed()
{
Toast.MakeText(this, "Authorization failed", ToastLength.Short).Show();
}
Upvotes: 1
Views: 86
Reputation: 89129
since your Auth task is async, all you should need to do is await the result and call the failed message if the result is false. You'll need to modify UsersAuthenTask to return true/false appropriately for each case.
login.Click += async delegate
{
activityIndicator.Visibility = Android.Views.ViewStates.Visible;
var auth = new UsersAuthentication();
var result = await auth.UsersAuthenTask(email.Text,password.Text, StartActivity, new Intent(this, typeof(IndMassActivity)));
if (!result) {
AuthorizationFailed();
}
};
Upvotes: 2