从Core(Portable)调用放置在Droid项目中的方法
Calling method placed in Droid project from Core(Portable)
我在一个解决方案中有两个项目。核心和机器人。在 Droid 项目中,我有一个方法需要在异步方法 IN CORE 完成其任务时调用。
我在 Core 中的代码是:
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;
}
我需要调用 Droid 中的方法 "AuthorizationFailed":
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();
}
由于您的 Auth 任务是异步的,您需要做的就是等待结果并在结果为假时调用失败消息。您需要针对每种情况将 UsersAuthenTask 修改为 return true/false。
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();
}
};
我在一个解决方案中有两个项目。核心和机器人。在 Droid 项目中,我有一个方法需要在异步方法 IN CORE 完成其任务时调用。 我在 Core 中的代码是:
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;
}
我需要调用 Droid 中的方法 "AuthorizationFailed":
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();
}
由于您的 Auth 任务是异步的,您需要做的就是等待结果并在结果为假时调用失败消息。您需要针对每种情况将 UsersAuthenTask 修改为 return true/false。
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();
}
};