Error in Fragment: “Already managing a GoogleApiClient with id 0”

后端 未结 10 1966
独厮守ぢ
独厮守ぢ 2020-12-13 08:16

Everything works right the first time, if you launch a second time you see this error:

FATAL EXCEPTION: main
Process         


        
10条回答
  •  旧时难觅i
    2020-12-13 08:43

    I faced a similar issue when I placed a login button in two different Fragments 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();
    

提交回复
热议问题