Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.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
在带有firebase实时数据库的android Studio应用程序中,登录按钮重定向到主页而不是用户页_Android_Firebase_Authentication - Fatal编程技术网

在带有firebase实时数据库的android Studio应用程序中,登录按钮重定向到主页而不是用户页

在带有firebase实时数据库的android Studio应用程序中,登录按钮重定向到主页而不是用户页,android,firebase,authentication,Android,Firebase,Authentication,当我点击登录按钮时,它会暂停一段时间,并自动重定向到我的应用程序主页面。 我在登录活动中使用了firebase实时数据库中的数据。 请帮我解决这个问题。。我浪费了两天时间来解决这个问题,但什么都没用 如果您有其他代码可以满足此要求,请告诉我。您正在Firebase实际注销用户之前启动LoginActivity。尝试添加一个FirebaseAuth.AuthStateListener,并在触发侦听器时启动LoginActivity。请看这篇文章:你能详细解释一下吗?因为我是android开发的新手

当我点击登录按钮时,它会暂停一段时间,并自动重定向到我的应用程序主页面。 我在登录活动中使用了firebase实时数据库中的数据。 请帮我解决这个问题。。我浪费了两天时间来解决这个问题,但什么都没用


如果您有其他代码可以满足此要求,请告诉我。

您正在Firebase实际注销用户之前启动LoginActivity。尝试添加一个
FirebaseAuth.AuthStateListener
,并在触发侦听器时启动LoginActivity。请看这篇文章:

你能详细解释一下吗?因为我是android开发的新手。看来你没有正确地注销。允许您登录并自动转到下一个活动。确保您已注销。Firebase使用internet,因此可能会造成代码延迟@Nilaytateli没有编写任何注销方法。我只是设置了打开下一个用户配置文件页面的意图。你在usrHome中有什么@NilayPatel检查(fbasePass.equals(appPass))是否运行,可以使用logcat@NilayPatel
    public class loginActivity extends AppCompatActivity {

    TextView signup;
    TextInputLayout phone,pass;
    Button btn_login;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        signup = findViewById(R.id.txt_signup);
        phone = findViewById(R.id.phone);
        pass = findViewById(R.id.pass);
        btn_login = findViewById(R.id.btn_login);
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                loginUser(view);
            }
        });

    }

    private boolean validatePhone(){
        String p = phone.getEditText().getText().toString();
        if(p.isEmpty()){
            phone.setError("field is empty!");
            return false;
        }
        else {
            phone.setError(null);
            phone.setErrorEnabled(false);
            return true;
        }
    }

    private boolean validatePass(){
        String p = pass.getEditText().getText().toString();
        if(p.isEmpty()){
            pass.setError("field is empty!");
            return false;
        }
        else {
            pass.setError(null);
            pass.setErrorEnabled(false);
            return true;
        }
    }

    public void loginUser(View v){
        if(!validatePhone() | !validatePass()){
            return;
        }
        else {
            isUser();
        }
    }

    private void isUser(){
        final String appPhone = Objects.requireNonNull(phone.getEditText()).getText().toString().trim();
        final String appPass = Objects.requireNonNull(pass.getEditText()).getText().toString().trim();

        DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("users");
        Query checkUser = databaseReference.orderByChild("phone").equalTo(appPhone);
        checkUser.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                if(dataSnapshot.exists()){
                    phone.setError(null);
                    phone.setErrorEnabled(false);

                    String fbasePass = dataSnapshot.child("pass").getValue(String.class);
                    assert fbasePass != null;
                    if(fbasePass.equals(appPass)){

                        phone.setError(null);
                        phone.setErrorEnabled(false);

                       // String uPhone = dataSnapshot.child(appPhone).child("phone").getValue(String.class);
                        String uPhone = dataSnapshot.child("phone").getValue(String.class);
                        String uAadhar = dataSnapshot.child("aadhar").getValue(String.class);
                        String ucity = dataSnapshot.child("city").getValue(String.class);
                        String ufname = dataSnapshot.child("fname").getValue(String.class);
                        String uemail = dataSnapshot.child("email").getValue(String.class);
                        Intent intent = new Intent(getApplicationContext(),usrHome.class);
                        intent.putExtra("phone",uPhone);
                        intent.putExtra("aadhar",uAadhar);
                        intent.putExtra("city",ucity);
                        intent.putExtra("fname",ufname);
                        intent.putExtra("email",uemail);
                        startActivity(intent);
                    }
                    else {
                        pass.setError("Wrong password");
                        pass.requestFocus();
                    }
                }
                else {
                    phone.setError("Please Create Account First");
                    phone.requestFocus();
                }
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {
            }
        });
    }
}