Google+ sign out from a different activity

前端 未结 9 1709
终归单人心
终归单人心 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:37

    Just add this on your new activity, where you want your logout-button for google+ to be there :

    @Override
    protected void onStart() {
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();
        mGoogleApiClient.connect();
        super.onStart();
    }
    

    and next:

     signout.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
                      new ResultCallback() {
                          @Override
                          public void onResult(Status status) {
                              // ...
                              Toast.makeText(getApplicationContext(),"Logged Out",Toast.LENGTH_SHORT).show();
                              Intent i=new Intent(getApplicationContext(),MainActivity.class);
                              startActivity(i);
                          }
                      });
          }
      });
    

提交回复
热议问题