简体   繁体   English

Firebase 实时数据库注销 Google 帐户

[英]Firebase Realtime Database Log Out Google Account

I have implemented Sign In the method using Google Accounts, my problem is the logout function doesn't behave what I want.我已经使用 Google 帐户实现了登录方法,我的问题是注销功能不符合我的要求。 I don't receive any error, it's just the code doesn't work properly.我没有收到任何错误,只是代码无法正常工作。

Can someone tell me what's wrong with this code?有人能告诉我这段代码有什么问题吗?

Options Fragment:选项片段:

        Preference logoutPreference = findPreference(getString(R.string.pref_key_logout));
        logoutPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                FirebaseAuth.getInstance().signOut();
                Intent broadcastIntent = new Intent();
                broadcastIntent.setAction("com.example.budgetapp.ACTION_LOGOUT");
                getActivity().sendBroadcast(broadcastIntent);
                getActivity().startActivity(new Intent(getActivity(), SignInActivity.class));
                getActivity().finish();
                return true;
            }
        });

Main Activity:主要活动:

    @Override
    protected void onResume() {
        super.onResume();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.example.budgetapp.ACTION_LOGOUT");
        receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                finish();
            }
        };
        registerReceiver(receiver, intentFilter);
    }

Why is the code not working?为什么代码不起作用? I'm using Firebase Realtime Database我正在使用 Firebase 实时数据库

Whenever I click Logout the app redirects me to Sign In Activity (which is good) but when I try to Sign In, it automatically signs in to the previous Google Account.每当我单击注销时,该应用程序都会将我重定向到登录活动(这很好),但是当我尝试登录时,它会自动登录到以前的 Google 帐户。

When you are using the following line of code:当您使用以下代码行时:

FirebaseAuth.getInstance().signOut();

It means that you are signing out only from Firebase.这意味着您仅从Firebase 退出。

Whenever I click Logout the app redirects me to Sign In Activity (which is good) but when I try to Sign In, it automatically signs in to the previous Google Account.每当我单击注销时,该应用程序都会将我重定向到登录活动(这很好),但是当我尝试登录时,它会自动登录到以前的 Google 帐户。

As I understand, you are using the Google Provider for authentication.据我了解,您正在使用 Google Provider 进行身份验证。 Signing out from Firebase doesn't mean that you are automatically signed out from Google.从 Firebase 退出并不意味着您会自动从 Google 退出。 To sign out from Google you have to explicitly add a call to GoogleSignInClient#signOut() method:要从 Google 注销,您必须明确添加对GoogleSignInClient#signOut()方法的调用:

googleSignInClient.signOut();

Don't also forget that the sign-out operation is asynchronous, meaning that you have to wait until the operation completes.也不要忘记注销操作是异步的,这意味着您必须等到操作完成。 Since this method returns an object of type Task<Void> , you can use addOnCompleteListener(OnCompleteListener listener) method, to know when you are completely signed out.由于此方法返回Task<Void>类型的对象,您可以使用addOnCompleteListener(OnCompleteListener listener)方法来了解您何时完全退出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM