Google+ sign out from a different activity

前端 未结 9 1706
终归单人心
终归单人心 2020-12-05 00:17

I have started using the Google+ API for android, and I have created a sign-in application following this tutorial:

https://developers.google.com/+/mobi

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 00:56

    sommesh's answer is perfect, but for less code you can use "Public Static Method" like this:

    public static GoogleApiClient mGoogleApiClient;
    ...
    ...
    public static void signOutFromGoogle() {
        Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
                new ResultCallback() {
                    @Override
                    public void onResult(Status status) {
                        //...
                    }
                });
    }
    

    And on your other Activity call it:

    Your_Google_Activity.mGoogleApiClient.connect();
    btnSignOut.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {            
            Your_Google_Activity.signOutFromGoogle();
        }
    });
    

提交回复
热议问题