Firebase Auth 不会在单击按钮时启动 Activity,但在关闭并重新打开应用程序时有效

在火力地堡验证是没有启动HomeActivitiy按钮点击。


它仅在重新打开应用程序时有效。


public class Auth1Activity extends 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, HomeActivity.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() {


可能出什么问题了?


噜噜哒
浏览 158回答 1
1回答

繁星点点滴滴

试试这个方法    authStateListener = new FirebaseAuth.AuthStateListener() {    @Override    public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {          firebaseUser = firebaseAuth.getCurrentUser();          if (firebaseUser != null) {          Intent intent = new Intent(Auth1Activity.this, HomeActivity.class);          startActivity(intent);          finish();        }    }};
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java