Everything works right the first time, if you launch a second time you see this error:
FATAL EXCEPTION: main
Process
You should call stopAutoManage() in the onPause()
method of your Fragment
like so:
@Override
public void onPause() {
super.onPause();
mGoogleApiClient.stopAutoManage(getActivity());
mGoogleApiClient.disconnect();
}
This works for me to avoid crashing issues using kotlin
private lateinit var googleApiClient: GoogleApiClient
And then just verify if the variable is already initialized
if(!::googleApiClient.isInitialized) {
googleApiClient = GoogleApiClient.Builder(context)
.enableAutoManage(activity, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, options)
.build()
}
To avoid further issue
@Override
public void onStop() {
super.onStop();
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
mGoogleApiClient.stopAutoManage((Activity) context);
mGoogleApiClient.disconnect();
}
}
You should call stopAutoManage()
in the onDestroy()
method of your fragment like so:
@Override
public void onDestroy() {
super.onDestroy();
mGoogleApiClient.stopAutoManage(getActivity());
mGoogleApiClient.disconnect();
}