Majid Hojati
Majid Hojati

Reputation: 1790

GoogleApiClient's enableAutoManage() needs a fragment activity but I have an activity

I want to logout from google account which is integrated into my application. I have this function

   public void logoutFromGooglePlus(Activity a) {
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .requestProfile()
                .build();
        GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(a.getBaseContext())
                .enableAutoManage(a /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addApi(Auth.GOOGLE_SIGN_IN_API)
                .build();
        mGoogleApiClient.connect();
        if (mGoogleApiClient.isConnected()) {
            Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
                    new ResultCallback<Status>() {
                        @Override
                        public void onResult(Status status) {


                        }
                    });
        } else {
            mGoogleApiClient.connect();   // It can send user to onConnected(), call logout again from there
        }
    }

As you can see I need to do it in an activity but here I have a problem enableAutoManage needs a fragmentActivity as input. But I have an activity. Can I cast activity as fragmentActivity easily?or there is some other methods to do it? thanks

Upvotes: 1

Views: 1146

Answers (1)

Chhornkimchheng
Chhornkimchheng

Reputation: 307

I have met the same problem as you but it works when i changed from activity to AppCompatActivity.

Hope it helps.

Upvotes: 3

Related Questions