由于GoogleApiClient导致Android崩溃

时间:2018-03-24 13:10:46

标签: java android google-places-api

基本上我正在尝试关闭GoogleApiClient,当我暂停或完成片段时,因为当我回到片段时崩溃了。

@Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);


    mGoogleApiClient = new GoogleApiClient
                .Builder(getActivity())
                .addApi(Places.GEO_DATA_API)
                .addApi(Places.PLACE_DETECTION_API)
                .enableAutoManage(getActivity(),this)
                .build();
}

@Override
    public void onPause() {
        super.onPause();
        mGoogleApiClient.disconnect();
    }
  

致命的例外:主要                                                                                  过程:com.example.conornaylor.fyp,PID:7055                                                                                  java.lang.IllegalStateException:已经在管理GoogleApiClient   id为0                                                                                      在com.google.android.gms.common.internal.zzbo.zza(未知来源)                                                                                      在com.google.android.gms.internal.zzbau.zza(未知来源)                                                                                      在   com.google.android.gms.common.api.GoogleApiClient $ Builder.build(未知   资源)                                                                                      在   com.example.conornaylor.fyp.event.CreateEventFragment.onViewCreated(CreateEventFragment.java:164)                                                                                      在   android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1343)                                                                                      在   android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1574)                                                                                      在   android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1641)                                                                                      在   android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:794)                                                                                      在   android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2415)                                                                                      在   android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2200)                                                                                      在   android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2153)                                                                                      在   android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2063)                                                                                      在   android.support.v4.app.FragmentManagerImpl $ 1.run(FragmentManager.java:725)                                                                                      在android.os.Handler.handleCallback(Handler.java:815)                                                                                      在android.os.Handler.dispatchMessage(Handler.java:104)                                                                                      在android.os.Looper.loop(Looper.java:207)                                                                                      在android.app.ActivityThread.main(ActivityThread.java:5728)                                                                                      at java.lang.reflect.Method.invoke(Native Method)                                                                                      在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:789)                                                                                      在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

1 个答案:

答案 0 :(得分:0)

通过在片段的onPause方法中调用mGoogleApiClient.stopAutoManage()来解决此问题。