0

I'm developing an application on Android and I want to allow users to log in with their google account. I managed the login but I am having problems with logout. I have a navigation drawer with the logout option in the end. Can someone help me implement logout?

I tried the code from https://developers.google.com/identity/sign-in/android/disconnect but it didn't work.

LogoutFragment

public class LogoutFragment extends Fragment {
private GoogleApiClient mGoogleApiClient;

private TextView mStatusTextView;
private ProgressDialog mProgressDialog;


public LogoutFragment() {
    // Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment

    signOut();
    return inflater.inflate(R.layout.fragment_logout, container, false);
}

public void signOut() {
    Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
            new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    // [START_EXCLUDE]
                     updateUI(false);
                    // [END_EXCLUDE]
                }
            });
}
 }
Khadija Daruwala
  • 1,185
  • 3
  • 25
  • 54

1 Answers1

0

First you have to init your mGoogleApiClient with the builder and then pass it to the sign-out method.

Check this sample code: Click

Seishin
  • 1,493
  • 1
  • 19
  • 30
  • i am pretty new to android. Can u please help me with the coding ? – Khadija Daruwala May 12 '16 at 11:54
  • Just check out the sample code I linked you to and you will find out how to build your GoogleApiClient and how to sign-in & logout. – Seishin May 12 '16 at 11:57
  • But i have a navigation drawer and that sample code says to make a logout button. How do i change it to work with "Logout" click in the navigation drawer – Khadija Daruwala May 12 '16 at 12:20
  • Just init the GoogleApiClient as it's in the sample, then pass it to the logout method as you do in your code now... The problem is that you don't initialize the GoogleApiClient. – Seishin May 12 '16 at 12:22
  • i did as u said. I am getting error: java.lang.RuntimeException: Unable to start activity java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context com.google.android.gms.common.api.GoogleApiClient.getContext()' on a null object reference – Khadija Daruwala May 12 '16 at 13:15