Answer the question
In order to leave comments, you need to log in
How to organize Google Login API to work in different Activities?
Hello.
Faced such a problem that the Google Login API does not work when switching to another Activity.
I created a class that looks like this:
public class GoogleLoginImpl
{
static String TAG = "GoogleLoginImpl";
public static GoogleApiClient googleApiClient = null;
public static GoogleSignInOptions googleSignInOptions = null;
public static GoogleSignInAccount googleSignInAccount = null;
public static void init(Context context)
{
googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
googleApiClient = new GoogleApiClient.Builder(context)
.enableAutoManage((FragmentActivity)context, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.e(TAG, "Connection failed : " + connectionResult.getErrorMessage());
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
.build();
googleApiClient.connect();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question