Error in Fragment: "Already managing a GoogleApiClient with id 0"
You should call stopAutoManage()
in the onPause()
method of your Fragment
like so:
@Override
public void onPause() {
super.onPause();
mGoogleApiClient.stopAutoManage(getActivity());
mGoogleApiClient.disconnect();
}
You should call stopAutoManage()
in the onPause()
method of your Fragment
:
@Override
public void onPause() {
super.onPause();
mGoogleClient.stopAutoManage(getActivity());
mGoogleClient.disconnect();
}
To avoid further issue
@Override
public void onStop() {
super.onStop();
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
mGoogleApiClient.stopAutoManage((Activity) context);
mGoogleApiClient.disconnect();
}
}
I faced a similar issue when I placed a login button in two different Fragment
s belonging to the same Activity
.
I solved this issue by assigning different ids to each automatically-managed GoogleApiClient
.
For example, in Fragment
1, while creating my GoogleApiClient
object I assigned 0 as the id:
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.enableAutoManage(getActivity(), 0, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
In Fragment
2, while creating my GoogleApiClient
object I assigned 1 as the id:
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.enableAutoManage(getActivity(), 1, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();