Android 谷歌自动登录安卓系统

Android 谷歌自动登录安卓系统,android,login,logout,Android,Login,Logout,我已经将谷歌登录集成到我的android应用程序中。为此,我有一个单独的登录活动。现在的问题是,在我注销并再次启动登录活动后,我会自动登录到google帐户 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login);

我已经将谷歌登录集成到我的android应用程序中。为此,我有一个单独的登录活动。现在的问题是,在我注销并再次启动登录活动后,我会自动登录到google帐户

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

        initUIElements();

        uiHelper = new UiLifecycleHelper(this, statusCallback);
        uiHelper.onCreate(savedInstanceState);
        gPlusHandler.mGoogleApiClient.connect();

        statusCallback = new FacebookSessionStatusCallBack();
        new UserInformationHandler(this).displayUserInformation();
    }

    private void initUIElements() {


        gPlusLoginButton = (SignInButton) findViewById(R.id.btn_sign_in);
        setGooglePlusButtonText(gPlusLoginButton, "GOOGLE");
        gPlusLoginButton
                .setOnClickListener(new android.view.View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        gPlusHandler.signInWithGplus();

                    }
                });
        if (gPlusHandler.mGoogleApiClient.isConnected()
                || gPlusHandler.mGoogleApiClient.isConnecting()) {
            Plus.AccountApi.clearDefaultAccount(gPlusHandler.mGoogleApiClient);
            gPlusHandler.mGoogleApiClient.disconnect();
            // gPlusHandler.mGoogleApiClient.connect();
        }

    }


    private void logoutAction() {
        llImageLayout.setVisibility(View.GONE);
        new UserInformationHandler(this).displayGuestInformation();
        switch (currentLoginType) {
        case GOOGLE:

            if (gPlusHandler.mGoogleApiClient.isConnected()) {
                Plus.AccountApi
                        .clearDefaultAccount(gPlusHandler.mGoogleApiClient);
                gPlusHandler.mGoogleApiClient.disconnect();
                gPlusHandler.mGoogleApiClient.connect();
            }

            break;
        case FACEBOOK:
            Session session = Session.getActiveSession();
            if (session != null) {
                session.closeAndClearTokenInformation();
            }
            break;
        case NONE:
        default:
            break;
        }

    }


    @Override
    protected void onStop() {
        super.onStop();

        if (gPlusHandler.mGoogleApiClient.isConnected()) {
            gPlusHandler.mGoogleApiClient.disconnect();
        }
    }

    protected void onStart() {
        super.onStart();
        gPlusHandler.mGoogleApiClient.connect();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == GoogleLoginHandler.RC_SIGN_IN) {
            if (resultCode != RESULT_OK) {
                gPlusHandler.mSignInClicked = false;
            }

            gPlusHandler.mIntentInProgress = false;

            if (!gPlusHandler.mGoogleApiClient.isConnecting()) {
                gPlusHandler.mGoogleApiClient.connect();
            }
        }
        if (resultCode == -1) {
            uiHelper.onActivityResult(requestCode, resultCode, data);
        }

    }

    /**
     * Logout From Facebook
     */
    public static void callFacebookLogout(Context context) {
        Session session = Session.getActiveSession();
        if (session != null) {

            if (!session.isClosed()) {
                session.closeAndClearTokenInformation();
                // clear your preferences if saved
            }
        } else {

            session = new Session(context);
            Session.setActiveSession(session);

            session.closeAndClearTokenInformation();
            // clear your preferences if saved

        }

    }

    public static void callGoogleLogout(BaseDefaultActivity activity) {
        try {
            activity.gPlusHandler.mGoogleApiClient = new GoogleApiClient.Builder(
                    activity).addConnectionCallbacks(activity.gPlusHandler)
                    .addOnConnectionFailedListener(activity.gPlusHandler)
                    .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN).build();
            if (activity.gPlusHandler.mGoogleApiClient.isConnected()
                    || activity.gPlusHandler.mGoogleApiClient.isConnecting()) {
                Plus.AccountApi
                        .clearDefaultAccount(activity.gPlusHandler.mGoogleApiClient);
                activity.gPlusHandler.mGoogleApiClient.disconnect();
                activity.gPlusHandler.mGoogleApiClient.connect();
            }
        } catch (Exception e) {
        }
    }

    }
}

建议您使用自定义按钮,而不是“登录按钮”。我尝试过这样做,但问题仍然存在