Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使登录和注册工作_Android_Login_Sharedpreferences_Realm - Fatal编程技术网

Android 使登录和注册工作

Android 使登录和注册工作,android,login,sharedpreferences,realm,Android,Login,Sharedpreferences,Realm,我目前正在做一个有网络应用和安卓应用的服务项目。目前web团队没有web服务,我需要实现表单的登录验证,并让用户能够注册。我已经尝试过领域,但我不是很了解它。 有什么帮助吗?您可以按照此操作 公共类LoginActivity扩展了AppCompatActivity{ 私有静态最终字符串TAG=“LoginActivity”; 私有静态最终整数请求\u注册=0; @InjectView(R.id.input\u email)EditText\u emailText; @InjectView(R

我目前正在做一个有网络应用和安卓应用的服务项目。目前web团队没有web服务,我需要实现表单的登录验证,并让用户能够注册。我已经尝试过领域,但我不是很了解它。 有什么帮助吗?

您可以按照此操作

公共类LoginActivity扩展了AppCompatActivity{
私有静态最终字符串TAG=“LoginActivity”;
私有静态最终整数请求\u注册=0;
@InjectView(R.id.input\u email)EditText\u emailText;
@InjectView(R.id.input_password)EditText_passwordText;
@InjectView(R.id.btn_登录)按钮_登录按钮;
@InjectView(R.id.link\u signup)TextView\u signupLink;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u登录);
注射(这个);
_loginButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
登录();
}
});
_signupLink.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
//启动注册活动
Intent Intent=newintent(getApplicationContext(),SignupActivity.class);
startActivityForResult(意向、请求和注册);
}
});
}
公共无效登录(){
Log.d(标记“登录”);
如果(!validate()){
onLoginFailed();
返回;
}
_loginButton.setEnabled(false);
final ProgressDialog ProgressDialog=新建ProgressDialog(LoginActivity.this,
R.style.AppTheme(黑色对话框);
progressDialog.setUndeterminate(true);
progressDialog.setMessage(“身份验证…”);
progressDialog.show();
字符串email=_emailText.getText().toString();
字符串密码=_passwordText.getText().toString();
//TODO:在这里实现您自己的身份验证逻辑。
新的android.os.Handler().postDelayed(
新的Runnable(){
公开募捐{
//在完成调用时,onloginsucess或onLoginFailed
onloginsucess();
//onLoginFailed();
progressDialog.disclose();
}
}, 3000);
}
@凌驾
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
if(requestCode==请求\注册){
if(resultCode==RESULT\u OK){
//TODO:在此处实现成功注册逻辑
//默认情况下,我们只是完成活动并自动登录
这个;
}
}
}
@凌驾
public void onBackPressed(){
//禁用返回Main活动
moveTaskToBack(真);
}
public void onloginsucess(){
_loginButton.setEnabled(true);
完成();
}
public void onLoginFailed(){
Toast.makeText(getBaseContext(),“登录失败”,Toast.LENGTH_LONG.show();
_loginButton.setEnabled(true);
}
公共布尔验证(){
布尔有效=真;
字符串email=_emailText.getText().toString();
字符串密码=_passwordText.getText().toString();
if(email.isEmpty()| | |!android.util.Patterns.email_ADDRESS.matcher(email.matches()){
_emailText.setError(“输入有效的电子邮件地址”);
有效=错误;
}否则{
_emailText.setError(空);
}
if(password.isEmpty()| | password.length()<4 | | password.length()>10){
_passwordText.setError(“4到10个字母数字字符之间”);
有效=错误;
}否则{
_passwordText.setError(null);
}
返回有效;
}
}

如果您正在查找登录页用户凭据验证,下面的代码片段可能会对您有所帮助

// validating email id
private boolean isValidEmail(String email) {
    String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
            + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

    Pattern pattern = Pattern.compile(EMAIL_PATTERN);
    Matcher matcher = pattern.matcher(email);
    return matcher.matches();
}

// validating password with retype password
private boolean isValidPassword(String pass) {
    if (pass != null && pass.length() > 6) {
        return true;
    }
    return false;
}

登录表单中的内容。您尝试了什么?尝试使用Web服务改型。它更稳定、更易于使用。按照给定的链接了解更多信息[好吧,领域是一个数据库,而不是验证库,也不是REST API实现:P
// validating email id
private boolean isValidEmail(String email) {
    String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
            + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

    Pattern pattern = Pattern.compile(EMAIL_PATTERN);
    Matcher matcher = pattern.matcher(email);
    return matcher.matches();
}

// validating password with retype password
private boolean isValidPassword(String pass) {
    if (pass != null && pass.length() > 6) {
        return true;
    }
    return false;
}