有意图的FireBase Auth错误

时间:2018-07-18 06:14:35

标签: java android firebase firebase-authentication

这是我的登录活动,当我单击“登录”按钮时,它不启动MainActivity,但是当我关闭并重新打开该应用程序时,它起作用了为什么要帮忙

公共类Auth1Activity扩展了AppCompatActivity {

String string_1;
String string_2;

private static final Boolean CHECK_EMAIL_VERIFIED = false;
private static final String TAG = "LoginActivity";

private FirebaseAuth firebaseAuth;
private FirebaseAuth.AuthStateListener authStateListener;
private FirebaseUser firebaseUser;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_auth_1);
    firebaseAuth = FirebaseAuth.getInstance();

    authStateListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {

        }

    };

    firebaseUser = firebaseAuth.getCurrentUser();

    if (firebaseUser != null) {

        Intent intent = new Intent(Auth1Activity.this, MainActivity.class);
        startActivity(intent);
        finish();

    }

    final EditText auth_layout_1_edit_text_1 = findViewById(R.id.auth_layout_1_edit_text_1);
    final EditText auth_layout_1_edit_text_2 = findViewById(R.id.auth_layout_1_edit_text_2);
    Button auth_layout_1_button = findViewById(R.id.auth_layout_1_button);

    auth_layout_1_button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            string_1 = auth_layout_1_edit_text_1.getText().toString();
            string_2 = auth_layout_1_edit_text_2.getText().toString();

            if (string_1.matches("") && string_2.matches("")) {

                auth_layout_1_edit_text_1.setError("Enter Email Address");
                auth_layout_1_edit_text_2.setError("Enter Password");

            } else if (!string_1.matches("") && !string_2.matches("")) {

                firebaseAuth.signInWithEmailAndPassword(string_1, string_2).addOnCompleteListener(Auth1Activity.this, new OnCompleteListener<AuthResult>() {

                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {

                        try {

                            if (firebaseUser.isEmailVerified()) {

                                Intent intent = new Intent(Auth1Activity.this, MainActivity.class);
                                startActivity(intent);
                                finish();

                            } else if (!firebaseUser.isEmailVerified()) {

                                Toast.makeText(Auth1Activity.this, "Sign Up Error Please Try Again.", Toast.LENGTH_SHORT).show();

                            }

                        } catch (NullPointerException ignored) {

                        }

                    }

                });

            }

        }

    });

}

@Override
public void onStart() {

    super.onStart();
    firebaseAuth.addAuthStateListener(authStateListener);

}

@Override
public void onStop() {

    super.onStop();

    if (authStateListener != null) {

        firebaseAuth.removeAuthStateListener(authStateListener);

    }

}

}

所以请告诉这个错误,现在真的很烦我帮助!!!如果您需要更多信息,请告诉

1 个答案:

答案 0 :(得分:0)

更改

void onClickItemFeed(int position, View view);

void onClickItemFeed(int position, View view,String text);

并通过在Viewholder内部进行onClickItemFeed.onClickItemFeed(getAdapterPosition(), view, editText.getText().toString());进行调用。

然后您在回调中包含文本。