在Android Studio中使用Firebase登出:getProviderData()返回null

时间:2018-12-17 17:34:24

标签: android firebase firebase-authentication google-authentication

我是android的新手,我用Firebase创建了一个简单的登录方法,其中包括使用Email,Facebook和google登录。我创建了波纹管退出功能。但是,当我单击退出方法时,第二次它不要求对facebook和google进行身份验证。有谁能够帮助我!如果有什么问题,请不要害怕,我对此很陌生。

private void OnClickSignOut(){
    sign_out_btn =(Button)findViewById(R.id.logout_btn);
    finish();
    //startActivity(new Intent(ProfileActivity.this,MainActivity.class));
    sign_out_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FirebaseAuth.getInstance().signOut();

            for (UserInfo user: FirebaseAuth.getInstance().getCurrentUser().getProviderData()) {
                if (user.getProviderId().equals("facebook.com")) {
                    System.out.println("User is signed in with Facebook");
                    LoginManager.getInstance().logOut();
                    startActivity(new Intent(ProfileActivity.this,MainActivity.class));
                }
                else if(user.getProviderId().equals("google.com")){
                    mGoogleSignInClient.signOut().addOnCompleteListener(ProfileActivity.this,
                            new OnCompleteListener<Void>() {
                                @Override
                                public void onComplete(@NonNull Task<Void> task) {
                                    startActivity(new Intent(ProfileActivity.this,MainActivity.class));
                                }
                            });
                }
                else{
                    startActivity(new Intent(ProfileActivity.this,MainActivity.class));
                }
            }
        }
    });
}

1 个答案:

答案 0 :(得分:0)

通过更改finish语句的位置可以解决初始问题。 但是修改代码后,我遇到了其他问题。标识符返回google.com,但未进入循环。在第二次单击注销按钮时应用崩溃。下面是代码和Logcat Logcat

                for (UserInfo user: FirebaseAuth.getInstance().getCurrentUser().getProviderData()) {
                   Log.d("***************1.Check provider "+user.getProviderId(),"check");
                    if (user.getProviderId().equals("facebook.com")) {
                        FirebaseAuth.getInstance().signOut();
                        System.out.println("User is signed in with Facebook");
                        LoginManager.getInstance().logOut();
                        startActivity(new Intent(ProfileActivity.this,MainActivity.class));
                        Log.d("Signout","Facebook Clicked");
                        finish();
                    }
                    Log.d("***************2.Check provider "+user.getProviderId(),"check");
                    if(user.getProviderId().equals("google.com")){
                        FirebaseAuth.getInstance().signOut();
                        mGoogleSignInClient.signOut().addOnCompleteListener(ProfileActivity.this,
                                new OnCompleteListener<Void>() {
                                    @Override
                                    public void onComplete(@NonNull Task<Void> task) {
                                        System.out.println("User is signed in with Google");
                                        startActivity(new Intent(ProfileActivity.this,MainActivity.class));
                                        Log.d("****Signout","Google Clicked");
                                        finish();
                                    }
                                });
                    }
                    else{
                        FirebaseAuth.getInstance().signOut();
                        startActivity(new Intent(ProfileActivity.this,MainActivity.class));
                        System.out.println("User is signed in with email");
                        Log.d("****Signout","email signedout");
                        finish();
                    }
                }