@Override
public void onClick(View v) {
if(v == buttonRegister){
registerUser();
}
}
private void registerUser() {
?*some code here*/
}
private void register(String name, String email, String password, String phone ) {
String urlSuffix = "?name="+name+"&email="+email+"&password="+password+"&phone="+phone;
class RegisterUser extends AsyncTask<String, Void, String> {
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(SignUpActivity.this, "Please Wait",null, true, true);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
}
@Override
protected String doInBackground(String... params) {
String s = params[0];
BufferedReader bufferedReader = null;
try {
URL url = new URL(REGISTER_URL+s);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String result;
result = bufferedReader.readLine();
return result;
}catch(Exception e){
return null;
}
}
}
RegisterUser ru = new RegisterUser();
ru.execute(urlSuffix);
}
答案 0 :(得分:1)
If you moved from login activity to this screen then you can use:
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
this.finish();
}
Otherwise you can start new activity like :
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
startActivity(new Intent(SignUpActivity.this,LoginActivity.class));
this.finish();
}
答案 1 :(得分:0)
这完全取决于您的REST API及其返回的内容,如果您可以从API发布json结果,那么它可以提供很多帮助。 如果它返回的消息类似于&#34;电子邮件已经存在&#34;然后你可以检查消息中是否存在该字符串,并做相应的操作
将onPostExecute方法更改为:
queryset.filter(answer_string__in = answerList)
答案 2 :(得分:0)
if($_SERVER['REQUEST_METHOD']=='GET'){
$name = $_GET['name'];
$password = $_GET['password'];
$email = $_GET['email'];
$phone = $_GET['phone'];
if($name == '' || $password == '' || $email == '' || $phone == '')
{
echo 'please fill all values';
}
else{
$check =$db->query("SELECT * FROM register WHERE email='".$_GET['email']."'";
$row=$check->num_rows;
if($row > 0)
{
echo 'email already exist';
}
else
{
$insert = $db->query("INSERT INTO register(`name`,`password`,`email`,`phone`) VALUES('".$_GET['name']."','".$_GET['password']."','".$_GET['email']."','".$_GET['phone']."')";
if($insert)
{
echo 'successfully registered';
} 其他 { 回声'哎呀!请再试一次!'; } } } } 其他{ 回声“错误”; }
答案 3 :(得分:0)
您应该使用LoginFragment
和RegisterFragment
的单个活动。
如果用户从LoginFragment登录,那么他可以直接转到新的Activity。
如果用户选择Register
,则需要在backstack上添加新的Fragment,看看他是否完成了注册。如果用户完成注册,则您只需弹出backstack
即可登陆LoginPage
。
仅限登录和注册我不建议您使用1 Activity
和2 Fragment.