当任务完成时,我需要去下一个活动,但它不会。它成功地在数据库中创建了一个帐户,但不会继续。
如下所示,我已经尝试过 oncomplete(task) 但是一旦我输入凭据并点击注册,它就会创建帐户但不会继续。
下面的代码(使用 refit 进行 Http 请求):
using Kula.API;
using Refit;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Kula
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
// set variables
Entry RinputEmail;
Entry RinputPassword;
Entry RinputUsername;
Entry RinputFullName;
IMyAPI myAPI;
APIRequestHelper apiRequestHelper;
public MainPage()
{
InitializeComponent();
myAPI = RestService.For<IMyAPI>("http://10.0.2.2:8080");
apiRequestHelper = new APIRequestHelper(myAPI);
// reference mainpage.xamal
RinputEmail = this.FindByName<Entry>("Remail");
RinputPassword = this.FindByName<Entry>("Rpassword");
RinputUsername = this.FindByName<Entry>("Rusername");
RinputFullName = this.FindByName<Entry>("Rfullname");
}
async private void GTLogin_Clicked(object sender, EventArgs e)
{
//navigate to Login page
await Navigation.PushAsync(new Login());
}
async private void registerUser_Clicked(object sender, EventArgs e)
{
await apiRequestHelper.RequestRegisterUserAsync((RinputEmail.Text).ToString(),
(RinputPassword.Text).ToString(), (RinputUsername.Text).ToString(),
(RinputFullName.Text).ToString()).ContinueWith((nextpage) => { Navigation.PushAsync(new
Login()); });
}
}
};
API_REQUEST_HELPER
namespace Kula.API
{
public class APIRequestHelper
{
IMyAPI myAPI;
public APIRequestHelper(IMyAPI myAPI)
{
this.myAPI = myAPI;
}
public async Task RequestRegisterUserAsync(string email, string
password, string username, string fullname)
{
//create params for request
Dictionary<string, object> data = new Dictionary<string,
object>();
data.Add("username", username);
data.Add("email", email);
data.Add("password", password);
data.Add("fullname", fullname);
await myAPI.RegisterUser(data);
}
/*
public async Task RequestRegisterUserAsync(string email, string
password, Boolean returntoken)
{
//create params for request
Dictionary<string, object> data = new Dictionary<string,
object>();
data.Add("email", email);
data.Add("password", password);
data.Add("returnSecureToken", returntoken);
string result = await myAPI.RegisterUsertwo(data);
}
*/
public async Task RequestLoginUserAsync(string email, string
password, Boolean returntoken)
{
//create params for request
Dictionary<string, object> data = new Dictionary<string,
object>();
data.Add("email", email);
data.Add("password", password);
data.Add("returnSecureToken", returntoken);
string result = await myAPI.LoginUser(data);
}
public async Task RequestLoginUserAsync(string email, string password)
{
//create params for request
Dictionary<string, object> data = new Dictionary<string,
object>();
data.Add("email", email);
data.Add("password", password);
string result = await myAPI.LoginUser(data);
}
public async Task RequestSaveProfileInfoAsync(string username, string fullname)
{
//create params for request
Dictionary<string, object> data = new Dictionary<string,
object>();
data.Add("username", username);
data.Add("fullname", fullname);
string result = await myAPI.SaveProfileInfo(data);
}
}
}
MY_API
using Kula.Models;
using Refit;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Kula.API
{
public interface IMyAPI
{
[Get("/Getuid")]
Task<string> GetUid();
[Post("/register")]
Task<string>
RegisterUser([Body(BodySerializationMethod.UrlEncoded)]
Dictionary<string, object> data);
[Get("/response")]
Task<string> GetResponse();
[Post("/accounts:signInWithPassword?key=")]
Task<string> LoginUser([Body(BodySerializationMethod.UrlEncoded)]
Dictionary<string, object> data);
[Post("/SaveProfileInfo")]
Task<string>
SaveProfileInfo([Body(BodySerializationMethod.UrlEncoded)]
Dictionary<string, object> data);
[Get("/GetProfileInfo")]
Task<List<string>> GetProfileInfo();
[Get("/GetSocialFeedTiles")]
Task<List<string>> GetSocialFeedTiles();
}